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 a certain condition is met, at which
point it stops.
quantity = 20
DO number = 1 TO 10 WHILE quantity < 50
quantity = qu 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 = qu number
SAY 'Quantity = 'quantity ' (Loop 'number')'
END
Nested DO Loops
Like nested IF/THEN/ELSE instructions, DO loops can also be within other DO
loops. A simple example follows:
DO outer = 1 TO 2
DO inner = 1 TO 2
SAY 'HIP'
END
SAY 'HURRAH'
END
The output from this example is:
HIP
HIP
HURRAH
HIP
HIP
HURRAH
If you need to leave a loop when a certain condition arises, use the LEAVE
instruction followed by the control variable of the loop. If the LEAVE instruction is for
the inner loop, you leave the inner loop and go to the outer loop. If the LEAVE
instruction is for the outer loop, you leave both loops.
To leave the inner loop in the preceding example, add an IF/THEN/ELSE instruction
that includes a LEAVE instruction after the IF instruction.
DO outer = 1 TO 2
DO inner = 1 TO 2
IFinner > 1 THEN
LEAVE inner
Using Looping Instructions
Chapter 4. Controlling the Flow Within an Exec
55
Содержание TSO/E REXX
Страница 1: ...z OS TSO E REXX User s Guide SA22 7791 00 ...
Страница 2: ......
Страница 3: ...z OS TSO E REXX User s Guide SA22 7791 00 ...
Страница 10: ...viii z OS V1R1 0 TSO E REXX User s Guide ...
Страница 12: ...x z OS V1R1 0 TSO E REXX User s Guide ...
Страница 14: ...xii z OS V1R1 0 TSO E REXX User s Guide ...
Страница 18: ...xvi z OS V1R1 0 TSO E REXX User s Guide ...
Страница 20: ...2 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 58: ...Tracing Expressions with the TRACE Instruction 40 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 78: ...60 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 86: ...Built In Functions 68 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 128: ...Issuing Other Types of Commands from an Exec 110 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 136: ...Debugging Execs 118 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 170: ...Protecting Elements in the Data Stack 152 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 201: ...Part 3 Appendixes Copyright IBM Corp 1988 2001 183 ...
Страница 202: ...184 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 222: ...Using Variables 204 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 226: ...208 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 238: ...220 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 241: ......