The various forms of the REXX DO statement lets you set up loops to perform repetitive tasks until a specified condition occurs.
The basic forms of the DO command are shown below:
do num loop - loop num times
do var = num_1 to num_2 loop - set the value of var to num_1 and loop,
incrementing the value of var by 1 each
time through the loop until the value of
var is greater than num_2, then leave
the loop.
do while condition_true - enter the loop only if condition_true is
satisfied, and continue looping for as long
as condition_true is satisfied.
do until condition_true - always enter the loop once, and continue
looping until condition_true is satisfied.
do forever - loop until exit is forced by the leave or
return commands.
You can use numeric constants, numeric variables, or functions that returns numeric values in place of num, num_1, and num_2 above. Loop control conditions can be specified using any combination of REXX variable and constant terms, REXX functions, and logical and comparison operators. For more information on these, see below, Related Tasks:
The DO loop starts with the DO statement, and ends with the END statement. Macro statements of any kind can appear inside the loop, including other loops. For example:
do reps = 5 to 10
statement 1
statement 2
num = 0
do while num < 3
statement a
statement b
num = num + 1
end
statement 4
end
You can force an early exit from any kind of DO loop by using the leave or return commands.
![]()
Specify Conditions in Editor Macros
Perform Constants and Variables in Editor
Macros
Perform REXX Functions in Editor Macros
