Exercises - Using Loops

Procedure

  1. What are the results of the following loops?

    1. DO digit = 1 TO 3
        SAY digit
      END
      SAY 'Digit is now' digit

    2. DO count = 10 BY -2 TO 6
        SAY count
      END
      SAY 'Count is now' count

    3. DO index = 10 TO 8
        SAY 'Hup! Hup! Hup!'
      END
      SAY 'Index is now' index
  2. Sometimes an infinite loop can occur when input to end the loop does not match what is expected. For instance, in the example of using the LEAVE Instruction, what happens when the input is Quit and a PARSE PULL instruction replaces the PULL instruction?
    PARSE PULL file_name

Results

ANSWERS
  1. The results of the repetitive loops are as follows:
    1.    1
         2
         3
         Digit is now 4

    2.    10
          8
          6
          Count is now 4

    3.     Index is now 10

  2. The program would be unable to leave the loop because Quit is not equal to QUIT. In this case, omitting the PARSE keyword is preferred because regardless of whether the input is quit, QUIT, or Quit, the language processor translates the input to uppercase before comparing it to QUIT.

Task Task

Feedback


Timestamp icon Last updated: Tuesday, 7 January 2014


http://pic.dhe.ibm.com/infocenter/cicsts/v5r1/topic/com.ibm.cics.rexx.doc//dfhrx/dfhrx00046.html