Language Reference

DO Statement with a WHILE Clause

conditionally executes statements iteratively

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

The inputs to the DO WHILE statement are as follows:
expression
is an expression that is evaluated at the top of the loop for being true or false.

variable
is the name of a variable indexing 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 a WHILE expression makes possible the conditional execution of a set of statements iteratively. The WHILE expression is evaluated at the top of the loop, and the statements inside the loop are executed repeatedly as long as the expression yields a nonzero or nonmissing value.

Note that the incrementing is done before the WHILE expression is tested. The following example demonstrates the incrementing:

  
    x=1; 
    do while(x<100); 
       x=x+1; 
    end; 
    print x;          /* x=100                           */
 
The next example increments the starting value by 2:
  
    y=1; 
    do x=1 to 100 by 2 while(y<200); 
       y=y#x; 
    end;              /* at end of loop, x=11 and y=945  */
 

Previous Page | Next Page | Top of Page