Kilowatt Software's
Classic Rexx Tutorial
Language Level 4.00 (TRL-2)

Select instruction group

The select instruction group performs an instruction (or sequence of instructions) among a set of possible alternatives. The select instruction group has the following syntactic structure.

Each when clause identifies a boolean expression to evaluate. A boolean expression is true if the value is '1', and false if the value is '0'. Any other values are invalid.

The booleanExpression is concluded when the end of the source line containing the when keyword is encountered. The source line may have been continued across multiple lines. If the then keyword is encountered on the same source line, or continued source lines, the booleanExpression is immediately concluded. Thus, the then keyword is special and cannot be used within the context of the booleanExpression.

At least one instruction must follow each then keyword. If multiple instructions follow the then keyword these must be bracketed within a do group.

The instructions that follow the otherwise keyword are optional. When multiple instructions are present these do NOT require an enclosing do group.

There must be at least one when phase. An otherwise clause is optional. HOWEVER if an otherwise clause is absent, AND if none of the when clauses evaluate to be true, then error code 7 (when or otherwise expected) is raised. An otherwise clause required in this circumstance. Hint: always provide and otherwise clause -- just in case.

After encountering the first when clause which evaluates to be true, the instruction(s) following the then keyword is/are performed. When the instruction(s) complete, processing continues with the instruction following the end instruction that is associated with the selectinstruction group. If none of the when clauses evaluate to be true, the optional instruction(s) following the otherwise keyword is/are performed. After these complete, processing continues with the instruction following the end instruction.

The following shows how a select instruction group can be used to validate program arguments.

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. Following the then keyword of a when clause an instruction must be provided. When an instruction is absent error code 9 (unexpected when or otherwise) is raised. For example, the following program is erroneous:

The correct way to program this in Rexx uses the NOP instruction instead.

A name is not permitted with the end instruction, when it concludes a select instruction group.


Kilowatt Software's -- Classic Rexx Tutorial -- Back to top
Click here if you have any comments or questions regarding this tutorial

Last updated on: 31 Aug 2002