Wednesday, October 21, 2015

Algoritma dan Pemrograman 04

Program Control - Repetition:

Repetition Definition

For
While
Do-While
Repetition Operation
Break vs Continue

One or more instruction repeated for certain amount of time

Number of repetition can be predefined (hard-coded in program)
or defined later at run time

Repetition/looping operation:

for
while
do-while

exp1 and exp3 can consist of several expression separated with
comma

Example:
void reverse(char ss[])

{
    int c,i,j;

    for(i=0, j=strlen(ss)-1; i<j; i++, j--){
        c=ss[i];
        ss[i]=ss[j];
        ss[j]=c;
    }
}

Infinite Loop



Loop with no stop condition can use “for-loop” by
removing all parameters (exp1, exp2, exp3). To
end the loop use break.

Nested Loop



Loop in a loop. The repetition operation will start
from the inner side loop.

sekan dan terima kasih

No comments:

Post a Comment