The For Statement

The For statement executes nested operators the specified number of times. The number of iterations 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 cycle one can use the Break statement to simultaneously pass control to the end point of the For statement, and also the Continue statement to pass control to the end point of nested cycle statements and go to the nest cycle work iteration.

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 cycle exit is executed as if a random integer value greater than 50 was generated.

See also:

Iteration Statements