EasyManuals Logo

IBM TSO/E REXX User Manual

IBM TSO/E REXX
242 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #61 background image
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?
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'
IF weather = 'fine' THEN
SAY 'What a lovely day!'
IF tenniscourt = '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

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the IBM TSO/E REXX and is the answer not in the manual?

IBM TSO/E REXX Specifications

General IconGeneral
BrandIBM
ModelTSO/E REXX
CategoryComputer Hardware
LanguageEnglish

Related product manuals