
IFexpression THEN
instruction
ELSE NOP
If you have more than one instruction for a condition, begin the set of instructions
with a DO and end them with an END.
IFweather = rainy THEN
SAY 'Find a good book.'
ELSE
DO
SAY 'Would you like to play tennis or golf?'
PULL answer
END
Without the enclosing DO and END, the language processor assumes only one
instruction for the ELSE clause.
Nested IF/THEN/ELSE Instructions
Sometimes it is necessary to have one or more IF/THEN/ELSE instructions within
other IF/THEN/ELSE instructions. Having one type of instruction within another is
called nesting. With nested IF instructions, it is important to match each IF with an
ELSE and each DO with an END.
IFweather = fine THEN
DO
SAY 'What a lovely day!'
IFtenniscourt = free THEN
SAY 'Shall we play tennis?'
ELSE NOP
END
ELSE
SAY 'Shall we take our raincoats?'
Not matching nested IFs to ELSEs and DOs to ENDs can have some surprising
results. If you eliminate the DOs and ENDs and the ELSE NOP, as in the following
example, what is the outcome?
Example of Missing Instructions
/******************************** REXX *****************************/
/* This exec demonstrates what can happen when you do not include */
/* DOs, ENDs, and ELSEs in nested IF/THEN/ELSE instructions.
*/
/*******************************************************************/
weather = 'fine'
tenniscourt = 'occupied'
IFweather = 'fine' THEN
SAY 'What a lovely day!'
IFtenniscourt = 'free' THEN
SAY 'Shall we play tennis?'
ELSE
SAY 'Shall we take our raincoats?'
By looking at the exec you might assume the ELSE belongs to the first IF. However,
the language processor associates an ELSE with the nearest unpaired IF. The
outcome is as follows:
What a lovely day!
Shall we take our raincoats?
Using Conditional Instructions
Chapter 4. Controlling the Flow Within an Exec
43
Содержание 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: ......