In the following discussion of the various forms of the FOR statement, the letter V stands for the control variable; AEXP1, AEXP2,... are arithmetic expressions; BEXP is a Boolean expression; and S1 is a statement.
FOR-DO Loop
Assume that a for-list element consists of only an initial part, such as the following:
FOR V:= AEXP1, AEXP2,... DO
In this case that for-list element designates only one value to be assigned to the control variable. Because no limiting condition is present, no test is made. After assignment of the arithmetic expression to the control variable, the statement following DO is executed, and the for-list element is considered exhausted.
FOR-DO Loop illustrates the FOR-DO loop.
FOR-STEP-UNTIL Loop
Assume a for-list element is of the form <initial part> STEP <arithmetic expression> UNTIL <arithmetic expression> such as the following:
FOR V:= AEXP1 STEP AEXP2 UNTIL AEXP3 DO <statement>
In this case, a new value is assigned to the control variable V before each execution of the statement following DO. First, the initial value, that of AEXP1, is assigned to the control variable. After each execution of the statement following DO, the assignment V:= V + AEXP2 is performed. Both AEXP2 and AEXP3 are reevaluated each time through the loop.
A test is made immediately after each assignment of a value to V to determine whether or not the value of V has passed the value of AEXP3. Whether AEXP3 is an upper or a lower limit depends on the sign of AEXP2; AEXP3 is an upper limit if AEXP2 is positive and a lower limit if AEXP2 is negative. If AEXP3 is an upper limit, then V has passed AEXP3 when the expression V LEQ AEXP3 is no longer TRUE. If AEXP3 is a lower limit, then V has passed AEXP3 when the expression V GEQ AEXP3 is no longer TRUE. If V has not passed AEXP3, the statement following DO is executed; otherwise, the for-list element is exhausted.
FOR-STEP-UNTIL Loop illustrates the FOR-STEP-UNTIL loop.
FOR-STEP-WHILE Loop
Assume a for-list element is of the form <initial part> STEP <arithmetic expression> WHILE <Boolean expression> such as the following:
FOR V := AEXP1 STEP AEXP2 WHILE BEXP DO <statement>
In this case a new value is assigned to the control variable V before each execution of the statement following DO. First, the initial value, that of AEXP1, is assigned to the control variable. After each execution of the statement following DO, the assignment V:= V + AEXP2 is performed. AEXP2 is reevaluated each time through the loop. After each assignment to V, the Boolean expression BEXP is evaluated and, if BEXP is TRUE, the statement following DO is executed. If BEXP is FALSE, this for-list element is exhausted.
FOR-STEP-WHILE Loop illustrates the FOR-STEP-WHILE loop.
FOR-WHILE Loop
Assume the for-list element is of the form <initial part> WHILE <Boolean expression>, such as the following:
FOR V:= AEXP1 WHILE BEXP DO
In this case the control variable V is assigned the value of AEXP1 before each execution of the statement following DO. AEXP1 is reevaluated for each assignment to V. After each assignment to V, the Boolean expression BEXP is evaluated. If the value of BEXP is TRUE, the statement following DO is executed. If the value of BEXP is FALSE, this for‑list element is exhausted. For example, in the following FOR statement if V had the value zero before execution of this statement, S1 would be executed five times:
FOR V:= V + 1 WHILE V LEQ 5 DO S1;
FOR-WHILE Loop illustrates the FOR-WHILE loop.





