FOR

The statement FOR FROM UPTO runs a model part a fixed number of times. The number of times that the model part will be executed depends on the FROM and UPTO formulae. When reaching the FOR FROM UPTO statement ITP calculates the formulae. The found values are rounded off. ITP will execute the model part and with every pass 1 will be added to the FROM value until the UPTO value is reached. When the UPTO value is reached the model part is executed one more time.

Definition FOR FROM UPTO statement:

FOR Loop_counter_variable_of_the_type_number
FROM formula_of_the_type_number
UPTO formula_of_the_type_number
DO
ITP-model part with declarations
OD

The loop counter variable, which is of type NUMBER, must be declared before use. You can give it any name you like. In this variable the loop counter is stored. The loop counter counts the number of loops passed. The loop counter is available in the DO … OD part of the FOR statement. This means that you can use the loop counter variable to, for instance, print the loop number in a result document.

Note

If the formula UPTO produces a smaller number then the formula FOR, the DO - OD will not be executed at all.

You can change the loop counter variable within the DO - OD part. This does not have any influence on the number of times that the DO - OD part will be executed, nor on the value of the variable within the next loop.

Example

#BEGIN
NUMBER counter
FOR counter
FROM 2
UPTO 6
DO
#
The counter is @(number(counter; 0)).
#
OD
END#

Result:
The counter is 2.
The counter is 3.
The counter is 4.
The counter is 5.
The counter is 6.

Note

Note that the function number( ) is used to format the counter so it is displayed without decimals.