Iterative statement

Iteration statements are used to specify the logic of a loop.

There are three kinds of rules :

FOR (condition of the loop) DO : this statement is used when the number of loops is known.

Exemple :

       FOR i:=0 TO 9 DO write(i+':');

The result will be 0:1:2:3:4:5:6:7:8:9:


WHILE (condition) DO : The WHILE keyword starts a control loop that is executed as long as the condition is satisfied. The loop is not executed at all if the expression is false at the start.








REPEAT... UNTIL (condition) : The REPEAT keyword starts a control loop that is always executed at least once, and which terminates when the condition is satisfied.

Example :

REPEAT

       write('Type Q to quit');

read(c);

UNTIL (c='Q');

Break the loop when the Q character is typed on the keyboard.