Types of REXX Clauses
REXX clauses can be: instructions, null clauses, and labels. Instructions can be keyword instructions,
assignments, or commands. The following example shows a program with these types of clauses. A
description of each type of clause follows the example.
Keyword Instructions
A keyword instruction tells the language processor to do something. It begins with a REXX keyword that
identifies what the language processor is to do. For example, DO can group instructions and execute them
repetitively, and IF tests whether a condition is met. SAY writes to the current terminal output device.
IF, THEN and ELSE are three keywords that work together in one instruction. Each keyword forms a
clause, which is a subset of an instruction. If the expression that follows the IF keyword is true, the
instruction that follows the THEN keyword is processed. Otherwise, the instruction that follows the ELSE
keyword is processed. (Note that a semicolon is needed before the ELSE if you are putting an ELSE
clause on the same line with a THEN.) If you want to put more than one instruction after a THEN or ELSE,
use a DO before the group of instructions and an END after them. More information about the IF
instruction appears in section “Using Conditional Instructions” on page 33.
The EXIT keyword tells the language processor to end the program. Using EXIT in the preceding example
is necessary because, otherwise, the language processor would execute the code in the subroutine after
the label sub:. EXIT is not necessary in some programs (such as those without subroutines), but it is good
programming practice to include it. More about EXIT appears in section “EXIT Instruction” on page 48.
Assignment
An assignment gives a value to a variable or changes the current value of a variable. A simple assignment
instruction is:
number = 4
In the preceding program, a simple assignment instruction is: store_a=0. The left side of the assignment
(before the equal sign) contains the name of the variable to receive a value from the right side (after the
equal sign). The right side can be an actual value (such as 4) or an expression. An expression is
something that needs to be evaluated, such as an arithmetic expression. The expression can contain
numbers, variables, or both.
number=4+4
number = number + 4
In the first example, the value of number is 8. If the second example directly followed the first in a program,
the value of number would become 12. More about expressions is in section “Using Expressions” on page
21.
/* QUOTA REXX program. Two car dealerships are competing to */
/* sell the most cars in 30 days. Who will win? */
store_a=0; store_b=0
DO 30
CALL sub
END
IF store_a>store_b THEN SAY "Store_a wins!"
ELSE IF store_b>store_a THEN SAY "Store_b wins!"
ELSE SAY "It's a tie!"
EXIT
sub:
store_a=store_a+RANDOM(0,20) /* RANDOM returns a random number in */
store_b=store_b+RANDOM(0,20) /* in specified range, here 0 to 20 */
RETURN
Writing and Running a REXX Program
Chapter 2. Writing and Running a REXX Program 9