REPETITION
Repetition / Looping :
-for
-while
-do-while
1.FOR
Syntax:
for(exp1; exp2; exp3) statement;
or:
for(exp1; exp2; exp3){
statement1;
statement2;
…….
}
exp1 : initialization
exp2 : conditional
exp3 : increment or decrement
exp1, exp2 and exp3 are optional
2.WHILE
-Di cek dulu baru dijalankan
-Adalah kondisi mengeksekusi blok kode yang ada diantaranya selama kondisi tersebut bernilai TRUE.
-Mempunyai kemiripan dengan looping “for”, namun sistemnya kurang lebih berjalan seperti dalam kondisi “IF”.
Syntax :
while (exp) statements;
or:
while(exp){
statement1;
statement2;
…..
}
3.DO – WHILE
-Dijalankan dulu baru di cek
-Merupakan statement pengulangan yang biasa digunakan untuk membuat menu dalam program.
-Secara umum proses do while sama dengan for ataupun while.
Syntax :
do{
< statements >;
} while(exp);
Break VC Continue
-Break :ending loop (for, while and do-while), end the switch operation
-Continue: skip all the rest of statements (subsequent to the skip statement) inside a repetition, and continue normally to the next loop.