DO REPEAT Statement

Description

The DO REPEAT statement executes a DO-group repetitively for different values of a variable.

The variable is assigned a start value that is used on the first iteration of the group. The REPEAT expression is evaluated before each subsequent iteration, and its result is assigned to the variable. If a WHILE option is included, the WHILE expression is evaluated before each iteration, including the first. If an UNTIL option is included, the UNTIL expression is evaluated at the end of each iteration. Unless the WHILE or UNTIL option is present, the loop repeats indefinitely.

The DO REPEAT statement causes the start expression to be evaluated and assigned to the index variable. If the WHILE option is given, the test expression is evaluated to produce a value b, which must be a bit-string of length greater than or equal to one. (See the section DO WHILE and DO UNTIL Statements.) If b is false, execution resumes with the statement following the corresponding END statement. If b is true or if a WHILE option is not given, the statements of the group are executed. When control reaches the END statement, if the UNTIL option is given, the test expression is evaluated to produce a value b. If b is true, execution resumes with the statement following the corresponding END statement. Otherwise, the next expression contained in the REPEAT option is evaluated and assigned to the index variable. Any WHILE option is again evaluated; if the value is true or the WHILE is omitted, the group is executed again.

index must be a reference to a variable whose data type makes it a suitable target for assignment of both start and next. Both start and next may be expressions of any data type, provided they both can be assigned to index.

The index reference is not completely reevaluated each time a next value is assigned to it. The original values of any subscripts, pointer qualifiers, or string lengths used in index are used in all subsequent assignments of next values. The next and test expressions are completely reevaluated each time.

The index variable must not be an array or structure, but it can be a reference to an element of an array or a member of a structure.

Example

DECLARE (HEAD,P) POINTER;
DECLARE 1 NODE BASED;
   2 VALUE FLOAT;
   2 NEXT POINTER;
DO P = HEAD REPEAT(P->NODE.NEXT) WHILE(P^=NULL);
   .
   .
   .
END;

The previous DO-group is executed repeatedly for each non-null pointer in the chain of nodes rooted in the pointer HEAD.