Download TSO/E REXX User's Guide
Transcript
Using Conditional Instructions When you put the entire instruction on one line, you must separate the THEN clause from the ELSE clause with a semi-colon. IF expression THEN instruction; ELSE instruction Generally, at least one instruction should follow the THEN and ELSE clauses. When either clause has no instructions, it is good programming practice to include NOP (no operation) next to the clause. IF expression 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. IF weather = 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. IF weather = fine THEN DO SAY 'What a lovely day!' IF tenniscourt = 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? Chapter 4. Controlling the Flow Within an Exec 4-3