DO Statement with an UNTIL Clause

DO UNTIL (expression) ;
DO variable = start TO stop <BY increment> UNTIL(expression) ;

The DO UNTIL statement conditionally executes statements iteratively.

The arguments to the DO UNTIL statement are as follows:

expression

is an expression that is evaluated at the bottom of the loop for being true or false.

variable

is the name of a variable that indexes the loop.

start

is the starting value for the looping variable.

stop

is the stopping value for the looping variable.

increment

is an increment value.

Using an UNTIL expression enables you to conditionally execute a set of statements iteratively. The UNTIL expression is evaluated at the bottom of the loop, and the statements inside the loop are executed repeatedly as long as the expression yields a zero or missing value. In the following example, the body of the loop executes until the value of X exceeds 100:

x = 1;
do until (x>100);
   x = x + 1;
end;
print x;   

Figure 23.93 Result of a DO-UNTIL Statement
x
101