The FOR statement constructs a loop consisting of one or more statements that are executed a specified number of times.
<for statement>
┌◄──────── , ────────┐ ── FOR ──<variable>── := ─┴─<for list element>─┴─ DO ──<statement>─────┤
<for list element>
──<initial part>─┬──────────────────┬──────────────────────────────────┤
└─<iteration part>─┘
<initial part>
──<arithmetic expression>──────────────────────────────────────────────┤
<iteration part>
──┬─ STEP <arithmetic expression> ─┬─ UNTIL <arithmetic expression> ─┬─┤ │ └─ WHILE <Boolean expression> ────┤ └─ WHILE <Boolean expression> ─────────────────────────────────────┘
The number of times a FOR loop is traversed is determined by a variable, called the control variable, which is initialized when the FOR statement is first entered, and which can be updated during each iteration of the loop.
The action of a FOR statement can be described by isolating the following three distinct steps:
-
Assignment of a value to the control variable
-
Test of the limiting condition
-
Execution of the statement following DO
Each type of <for list element> syntax specifies a different process. However, all of these processes have one property in common: the initial value assigned to the control variable is that of the arithmetic expression in the <initial part> construct.
The <for list element> construct establishes which values are assigned to the control variable and which test to make of the control variable to determine whether or not the statement following DO is executed. When a for-list element is exhausted, the next for-list element, if any, is evaluated, progressing from left to right. When all for-list elements have been used, the FOR statement is considered completed, and execution continues with the statement following the FOR statement. The statement following DO can transfer control outside the FOR statement, in which case some for-list elements might not have been exhausted before the FOR statement is exited.

