IF…THEN…ELSE Instructions

The examples of IF…THEN…ELSE instructions in previous chapters demonstrate the two-choice selection. In a flow chart, this appears as follows:

dfhrx001

As a REXX instruction, the flowchart example looks like:
IF expression THEN instruction
ELSE instruction
You can also arrange the clauses in one of the following ways to enhance readability:
 IF expression THEN
instruction
ELSE
instruction

or

IF expression
THEN
instruction
ELSE
instruction
When you put the entire instruction on one line, you must use a semicolon before the ELSE to separate the THEN clause from the ELSE clause.
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
PULL playgolf /* Gets data from input stream */
If playgolf='YES' THEN SAY 'Fore!'
END

Without the enclosing DO and END, the language processor assumes only one instruction for the ELSE clause.



dfhrxay.html | Timestamp icon Last updated: Monday, 5 June 2017