z/OS TSO/E REXX User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Exercises - Combining Loops

z/OS TSO/E REXX User's Guide
SA32-0982-00

  1. What happens when the following exec runs?
    DO outer = 1 TO 3
      SAY                  /* Write a blank line                       */
      DO inner = 1 TO 3
        SAY 'Outer' outer 'Inner' inner
      END
    END
  2. Now what happens when the LEAVE instruction is added?
    DO outer = 1 TO 3
      SAY                  /* Write a blank line                       */
      DO inner = 1 TO 3
        IF inner = 2 THEN
          LEAVE inner
        ELSE
          SAY 'Outer' outer 'Inner' inner
      END
    END
ANSWERS
  1. When this example runs, you see on your screen the following:
       Outer 1  Inner 1
       Outer 1  Inner 2
       Outer 1  Inner 3
    
       Outer 2  Inner 1
       Outer 2  Inner 2
       Outer 2  Inner 3
    
       Outer 3  Inner 1
       Outer 3  Inner 2
       Outer 3  Inner 3
  2. The result is one line of output for each of the inner loops.
       Outer 1  Inner 1
    
       Outer 2  Inner 1
    
       Outer 3  Inner 1

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014