next up previous contents index
Next: Shattered Control Flow Up: Compound Statements Previous: Conditional Control Flow

Iterative Control Flow

     

The for, while and repeat statements specify iteration. The for statement's index variable is initialized to initial and is compared against the final value before each iteration. The for...to statement increments the value of the index variable by one after each iteration and terminates when the value of index is greater than final. The for...downto statement decrements the value of the index variable by one after each iteration and terminates when the value of index is less than final. The optional step expression specifies the magnitude of the increment or decrement; step must be an integral expression that is greater than zero (negative or zero values of step can lead to infinite loops). It is legal to modify the index value inside the body of the statement.

    The while statement evaluates its conditional expression before each iteration of its loop body. The loop terminates when the expression evaluates to false. The repeat statement is similar to the while except it evaluates its conditional expression at the end of each iteration.



Kay Nettle
Fri Feb 21 21:14:29 CST 1997