The For Statement

The For statement executes embedded operators the specified number of times. The iteration number depends on the start and end value of the iteration variable and on its step.

for-statement:

For   identifier  :=   expression   To   expression   for-step-clauseopt   Do   block   End For

for-step-clause:

Step expression

Each For statement includes the identifier of the variable named the iteration variable. It also contains an expression that determines the start and end value of the iteration variable and the step of its change. If no iteration variable step is specified, it is considered to be equal to one. The statement is executed as follows:

Within the embedded statement block of the For statement one can use the Break statement to immediately transfer control to the end point of the For statement, and the Continue statement to transfer control to the end point of embedded statements.

Example

Private Sub TestFor();
Var
    i, j: integer;
    Rnd: Random = New Random();
Begin
    For i := 0 To 100 Do
        j := Rnd.Next(0100);
        If j > 50 Then
            Break;
        End If;
    End For;
End Sub;

On executing the example loop exit is executed as if a random integer value greater than 50 was generated.

See also:

Iteration Statements