Combining Types of Loops

You can combine repetitive and conditional loops to create a compound loop. The following loop is set to repeat 10 times while the quantity is less than 50, at which point it stops.
quantity = 20
DO number = 1 TO 10 WHILE quantity < 50
  quantity = quantity + number
  SAY 'Quantity = 'quantity '  (Loop 'number')'
END
The result of this example is as follows:
Quantity = 21   (Loop 1)
Quantity = 23   (Loop 2)
Quantity = 26   (Loop 3)
Quantity = 30   (Loop 4)
Quantity = 35   (Loop 5)
Quantity = 41   (Loop 6)
Quantity = 48   (Loop 7)
Quantity = 56   (Loop 8)
You can substitute a DO UNTIL loop, change the comparison operator from < to >, and get the same results.
quantity = 20
DO number = 1 TO 10 UNTIL quantity > 50
  quantity = quantity + number
  SAY 'Quantity = 'quantity '  (Loop 'number')'
END

Concept Concept

Feedback


Timestamp icon Last updated: Tuesday, 7 January 2014


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