There are two ways to conclude an instruction. An instruction is implicitly considered to be complete when the end of a source line is encountered, unless the line was continued. Alternatively, an instruction can be explicitly terminated by a semicolon. This allows a source line to contain multiple instructions, but this practice is discouraged.
Semicolons are generally never necessary in Rexx programs, because the end of source lines automatically terminates instructions. There is one principal exception. When an else clause is on the same source line of an if instruction's then clause, then a semicolon is required to mark the conclusion of the instruction following the then keyword. For example,
say 'What is your favorite color?'
color = translate( linein() ) if color = 'RED' then say "that's a hot color" else say 'ok' When the color that is entered is 'RED' the following output appears -- SURPRISE! that's a hot color ELSE SAY ok |
The correct form of the if instruction has a semicolon prior to the elsekeyword:
if color = 'RED' then say "that's a hot color" ; else say 'ok' |
However, it is highly recommended that you structure the logic as follows:
if color = 'RED' then
say "that's a hot color" else say 'ok' |
Semicolons are necessary to divide instructions that are processed by an interpret instruction. Similarly, semicolons divide instructions that are entered at an interactive trace prompt.
Other programming languages use isolated semicolons as empty instructions. In Rexx programs, isolated semicolons are not empty instructions. The NOP instruction is explicitly used for this purpose instead. For example, the following program is erroneous:
say 'Please enter your favorite color:'
parse pull color if color = 'RED' then ; /* <-- ERROR !!! */ else say 'your favorite color is not red' |
The correct way to program this in Rexx uses the NOP instruction instead.
say 'Please enter your favorite color:'
parse pull color if color = 'RED' then nop /* <-- ah, this is correct */ else say 'your favorite color is not red' |
You might have seen Rexx programs that have multiple assignment instructions on a single line, especially in books. Your programs will be easier to understand if the assignments are placed on separate lines. Consider the following example.
drop a3; a33 = 7; k = 3; fred='K'; list.5 = '?' |
drop a3 a33 = 7 k = 3 fred='K' list.5 = '?' |
There is another Rexx idiom for performing multiple assignments. This uses the PARSE instruction. The above assignments can be accomplished as follows:
drop a3 /* the parse instruction can not drop values */ parse value '7 3 K ?' with a33 k fred list.5 |