Making Decisions(IF THEN)

In the procedures discussed in earlier sections, instructions were run sequentially. In this section, you will see how you can control the order in which instructions are run. Depending upon the user's interaction with your procedure, you may choose not to run some of your lines of code.

Two instructions that let you make decisions in your procedures are the IF and SELECT instructions. The IF instruction is similar to the OS/2 IF command-it lets you control whether the next instruction is run or skipped. The SELECT instruction lets you choose one instruction to run from a group of instructions.

The IF instruction is used with a THEN instruction to make a decision. The interpreter runs the instruction if the expression is true; for example:

IF answer = "YES"
 THEN
 SAY "OK!"
In the previous example, the SAY instruction is run only if answer has the value of YES.

Grouping Instructions Using DO and END

To tell the interpreter to run a list of instructions after the THEN instruction, use:

DO
   Instruction1
   Instruction2
   Instruction3
END

The DO instruction and its END instruction tell the interpreter to treat any instructions between them as a single instruction.


[Back: REXX Features]
[Next: The ELSE Instruction]