Increment control
SYNTAX:
increment_control = variable_id ':=' bound_1 TO bound_2 [ BY increment ] .
bound_1 = numeric_expression .
bound_2 = numeric_expression .
increment = numeric_expression .
The increment control causes the body of the repeat statement to be executed for successive values in a sequence. Upon entry to the repeat statement, the implicitly declared variable variable_id, of type number, is set to the value of bound_1. After each iteration, the value of variable_id is set to variable_id + increment. If increment is not specified, the default value of one (1) is used. If variable_id is between bound_1 and bound_2 (including the case where variable_id = bound_2), the execution of the repeat statement proceeds.
Rules and restrictions:
The numeric_expressions representing the bound_1, bound_2 and increment shall evaluate to numeric values.
The numeric_expressions representing the bounds and the increment are evaluated once on entry to the repeat statement.
If any of the numeric_expressions representing the bounds or the increment have the value indeterminate the repeat statement is not executed.
Upon first evaluation of the increment control statement the following conditions are checked for:
- if increment is positive and bound_1 > bound_2, the repeat statement is not executed;
- if increment is negative and bound_1 < bound_2, the repeat statement is not executed;
- if increment is zero (0), the repeat statement is not executed;
- if none of the above is true, the repeat statement is executed until the value of variable_id is outside the bounds specified or one of the other repeat control statements, if present, terminates the execution.
The loop variable is initialized to bound_1 at the beginning of the first iteration cycle and incremented by increment at the beginning of each subsequent cycle.
The body of the repeat statement shall not modify the value of the loop variable.
The repeat statement establishes a local scope in which the loop variable variable_id is implicitly declared as a number variable. Thus any declaration of variable_id in the surrounding scope is hidden within the repeat statement, and the value of the loop variable is not available outside the repeat statement.