Language Reference

DO and END Statements

group statements as a unit

DO ;
           statements
END ;

The DO statement specifies that the statements following the DO statement be executed as a group until a matching END statement appears. DO statements often appear in IF-THEN/ELSE statements, where they designate groups of statements to be performed when the IF condition is true or false.

For example, consider the following statements:

  
    if x=y then 
       do; 
          i=i+l; 
          print x; 
       end; 
    print y;
 
The statements between the DO and END statements (called the DO group) are executed only if x=y; that is, they are executed only if all elements of x are equal to the corresponding elements of y. If any element of x is not equal to the corresponding element of y, the statements in the DO group are skipped and the next statement is executed. In this case, the next statement executed is as follows:
  
    print y;
 
DO groups can be nested; there is no limit imposed on the number of nested DO groups.

Here is an example of nested DO groups:

  
    if y>z then 
       do; 
          if z=0 then 
             do; 
                z=b*c; 
                x=2#y; 
             end; 
       end;
 
It is good practice to indent the statements in a DO group as shown in the preceding example so that their positions indicate their levels of nesting.

Previous Page | Next Page | Top of Page