The OPTMODEL Procedure

LEAVE Statement

LEAVE ;

The LEAVE statement terminates the execution of the entire loop body (iterative DO, DO UNTIL, DO WHILE, or FOR) that immediately contains the LEAVE statement. Execution resumes at the statement that follows the loop. The following example demonstrates a simple use of the LEAVE statement:

    proc optmodel;
       number i, j;
       do i = 1..5;
          do j = 1..4;
    	    if i >= 3 and j = 2 then leave;
    	 end;
       print i j;
       end;
 

The results from this code are displayed in Output 6.18.

The OPTMODEL Procedure

i j
1 5

i j
2 5

i j
3 2

i j
4 2

i j
5 2


Figure 6.18: LEAVE Statement Output

For values of i equal to 1 or 2, the inner loop continues uninterrupted, leaving j with a value of 5. For values of i equal to 3, 4, or 5, the inner loop terminates early, leaving j with a value of 2.

Previous Page | Next Page | Top of Page