IF/THEN/ELSE Instructions

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

IKJC3001
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 separate the THEN clause from the ELSE clause with a semicolon.
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.