Begins a sequence of statements to be executed as a group, possibly to be executed iteratively.
DO {while-until-spec | [index = iteration-spec[,iteration-spec]…]
|[index = start {UPTHRU|DOWNTHRU} finish][1] [repeat-spec][while-until-spec]
| FOREVER | LOOP};
{WHILE | UNTIL}(test-expression)
start[to-by-spec|repeat-spec][while-until-spec]
{TO finish[BY increment] | BY increment[TO finish]}
REPEAT next
DCL I FIXED BIN (15); ON CONVERSION BEGIN; PUT SKIP LIST ('Conversion triggered'); STOP; END; DO FOREVER; GET LIST (I) ; PUT LIST (I) ; PUT SKIP; IF I = 0 THEN LEAVE; END;
The following topics explain each DO statement. In all of these discussions, you can assume that the DO-group neither transfers control out of the group nor skips statements within the group when the statements of the group are executed once, twice, n times, and so on. However, any DO-group can contain IF statements, other DO-groups, RETURN, or GOTO statements that alter the order of execution.
Control cannot be transferred initially into a non-simple DO-group except by executing that DO-group's DO statement. Also, if control is transferred out of a non-simple DO-group (other than by a procedure or function call), control cannot generally be transferred back into the group. Violation of these rules causes unpredictable results.
Description
The DO statement begins a sequence of statements to be executed in a group. The group ends with the non-executable statement END.
A DO-group is executed a variable number of times under the control of its DO statement.
A DO statement cannot be used as an ON-unit, but can appear anywhere within a procedure or BEGIN block, including a THEN or ELSE clause of an IF statement or as an object of a WHEN or OTHERWISE clause.
specifies an infinite loop. The GOTO or LEAVE statement, or terminating the program, is the only means of exiting the loop.
is the equivalent.