/MACRO_SYNTAX_Branching

Macro statements for general flow control.

/MACRO/SYNTAX/Branching/CASE

Select one of many branches.

CASE expression IN (label) statement [ statements ] ... (label) statement [ statements ] ENDCASE

The CASE switch evaluates the string expression and compares it one by one against the label lists until the first match is found. If a match is found the statements up to the next label are executed before skipping to the statement following the ENDCASE. None of the statements are executed if there is no match with any label.

Each label is a string constant and the comparison witht the selection expression is case-sensitive. If the same statement sequence should be executed for distinct values a comma-separated list of values can be used.

The "*" character in a label item acts as wildcard matching any string of zero or more characters, i.e., "(*)" constitutes the default label.

/MACRO/SYNTAX/Branching/GOTO_and_IF_GOTO

Unconditional and conditional branching.

GOTO label

The simplest form of flow control is provided by the GOTO statement which continues execution at the statement following the target "label:". If the jump leads into the scope of a block statement, for example a DO-loop, the result is undefined.

The target may be given by a variable containing the actual label name.

IF expression GOTO label

This old-fashioned construct is equivalent to

IF expression THEN GOTO label ENDIF

/MACRO/SYNTAX/Branching/IF_THEN

Conditional execution of statement blocks.

IF expression THEN statements ELSEIF expression THEN statements ... ELSEIF expression THEN statements ELSE statements ENDIF

The general IF construct executes the statements following the first IF/ELSEIF clause for with the boolean expression is true and then continues at the statement following the ENDIF. The ELSEIF clause can be repeated any number of times or can be omitted altogether. If none of the expressions is true, the statements following the optional ELSE clause are executed.

/MACRO/SYNTAX/Branching/ON_ERROR

Installing an error handler.

Each command returns a status code which should be zero if the operation was successful or non-zero if any kind of error condition occurred. The status code can be tested by $IQUEST(1) system function.

ON ERROR GOTO label

installs an error handler which tests the status code after each command and branches to the given label when a non-zero value is found. The error handler is local to each macro.

ON ERROR EXITM [ expression ]

and

ON ERROR STOPM

are short-hand notations for a corresponding EXITM or STOPM statement at the targat label.

ON ERROR CONTINUE

continues execution with the next command independent of the status code. This is the initial setting when entering a macro.

OFF ERROR

An error handler can be deactivated by this statement.

ON ERROR

An error handler can be reactivated by this statement.