REPETITION
–> One or more instruction repeated for certain amount of time
Repetition operation
1. for
syntax:
for (expression1;expression2;expression3)statement;
or
for(exp1;exp2;exp3)
contoh:
void reverse (char ss[]){
int e,i,j;
for(i=0;j=strlen(ss)-1;i<j,i++,j–){
c=ss[i];
ss[i]=ss[j];
ssj[j]=c;
}
}
infinite for
–> loop with no stop condition. to end the loop, use break
nested loop
–> for dalam for
2. Repetition while
syntax: while(expression) statements;
pros: Tak mungkin salah
3. Repetition Do-While
syntax:
do{statement}
while(exression)
pros: statement di jalankan terlebih dahulu baru di cek.