Purpose
Begins a sequence of statements to be executed as a group, possibly to be executed iteratively.
Syntax
DO [while-until-spec]|[index = iteration-spec[,iteration-spec]…]| FOREVER | LOOP;
where
while-until-spec is:
WHILE(test-expression)[UNTIL(test-expression)]
or
UNTIL(test-expression)[WHILE(test-expression)]
and where
iteration-spec is:
start[to-by-spec|repeat-spec][while-until-spec]
where
to-by-spec is:
TO finish[BY increment]
or
BY increment[TO finish]
and where
repeat-spec is:
REPEAT next
Parameters
-
test-expression
- Any expression that yields a scalar bit string value of length >= 1. If any bit of the value is 1, the
test-expression is true; otherwise, it is false.
test-expression must be enclosed in parentheses.
-
index
- A reference to a scalar variable.
- start, next, finish, and
increment
- Expressions valid for assignment to
index.
Description
The DO statement begins a sequence of statements to be executed in a group. The group ends with the nonexecutable 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.
The following sections 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.