for

Repeats a list of statements while looping a variable over a set of values. The set of values is defined by a start value and an end value, and optionally a stepping value used to increase the variable. If the stepping value is not given, stepping is done by one.

Looping ends as soon as the variable value has been stepped beyond to given end value.

Note that the loop variable will be local to any function containing the for statement.

Syntax

    for variable-name = numeric-expression
      to numeric-expression do
        block-of-code
    done;

or

    for variable-name = numeric-expression
      to numeric-expression
      step numeric-expression do
        block-of-code
    done;

Example

    for x = 10 to 1 step -1 do
        println("x is ", x);
    done;