Three types of iterative statement are provided: the for-statement providing definite iteration and the while- and repeat-statements providing indefinite iteration.
Iteration may be performed over an arithmetic progression of integers or over any finite enumerated structure. Iterative statements may be nested. If nested iterations occur over the same enumerated structure, abbreviations such as for x, y in X do may be used; the leftmost identifier will correspond to the outermost loop, etc.
Early termination of the body of loop may be specified through use of the `jump' commands breakcontinue. and
Definite Iteration
for i := expr_1 to expr_2 by expr_3 do : ->
The expressions in this for loop must return integer values, say b, e and s (for `begin', `end' and `step') respectively. The loop is ignored if either s>0 and b>e, or s<0 s="0" k="0,">0) or b + k.s>e (for e<0).>If the required step size is 1, the above may be abbreviated to:
for i := expr_1 to expr_2 do : ->
for x in S do : ->
Each of the elements of the finite enumerated structure S will be assigned to x in succession, and each time the statements will be executed.
Indefinite Iteration
while boolexpr do statements end while : ->
Check whether or not the Boolean expression has the value {true}; if it has, execute the statements. Repeat this until the expression assumes the value {false}, in which case statements following the end while; will be executed.
No comments:
Post a Comment