The iterative DO sequence creates a loop that executes if a numeric
value stays within a given range of values. The values can be variables
derived from CLIST processing. The iterative DO sequence has the
following structure:
DO variable = from_expression TO to_expression +
[BY by_expression]
⋮
(action)
⋮
END
where:
- variable
- is the control variable for the loop. Its value changes each
time the loop executes, increasing by one (the default) or by a value
that you specify in the BY expression.
- from_expression
- is a decimal integer, or an expression that evaluates to a decimal
integer, from which the control variable starts. The CLIST sets the
control variable to this value when the loop begins.
- to_expression
- is a decimal integer, or an expression that evaluates to a decimal
integer, that the control variable must increase or decrease to.
The CLIST executes the loop if the value of the control variable stays
within the range created by the FROM and TO expressions.
- by_expression
- is a decimal integer, or an expression that evaluates to a decimal
integer, by which the control variable increases or decreases. The
default value is one. After the loop executes, the control variable
increases or decreases by this amount. If the control variable is
no longer within the FROM-TO range, execution continues at the instruction
after the END statement.
For example, a CLIST need to execute the following loop ten times:
DO &count = 1 to 10 /* using default BY, increase &count by one
/* each time through the loop
⋮
END /* &count is now equal to 11
And a CLIST need to execute the following loop five times:
DO &count = 1 TO 10 BY 2 /* increase &count by two
/* each time through the loop
⋮
END /* &count is now equal to 12
The FROM, TO, and BY expressions can all contain CLIST variables:
DO &count = &min TO &max BY &increment
⋮
END