DO IF Structures (MATRIX-END MATRIX command)
A DO IF
structure
in a matrix program affects the flow of control exactly as the analogous
commands affect a transformation program, except that missing-value
considerations do not arise in a matrix program. The syntax of the DO IF
structure is as follows:
DO IF [(]logical expression[)]
matrix statements
[ELSE IF [(]logical expression[)]]
matrix statements
[ELSE IF...]
.
.
.
[ELSE]
matrix statements
END IF.
- The
DO IF
statement marks the beginning of the structure, and theEND IF
statement marks its end. - The
ELSE IF
statement is optional and can be repeated as many times as desired within the structure. - The
ELSE
statement is optional. It can be used only once and must follow anyELSE IF
statements. - The
END IF
statement must follow anyELSE IF
andELSE
statements. - The
DO IF
andELSE IF
statements must contain a logical expression, normally one involving the relational operatorsEQ
,GT
, and so on. However, the matrix language allows any expression that evaluates to a scalar to be used as the logical expression. Scalars greater than 0 are considered true, and scalars less than or equal to 0 are considered false.
A DO IF
structure
affects the flow of control within a matrix program as follows:
- If the logical expression on the
DO IF
statement is true, the statements immediately following theDO IF
are executed up to the nextELSE IF
orELSE
in the structure. Control then passes to the first statement following theEND IF
for that structure. - If the expression on the
DO IF
statement is false, control passes to the firstELSE IF
, where the logical expression is evaluated. If this expression is true, statements following theELSE IF
are executed up to the nextELSE IF
orELSE
statement, and control passes to the first statement following theEND IF
for that structure. - If the expressions on the
DO IF
and the firstELSE IF
statements are both false, control passes to the nextELSE IF
, where that logical expression is evaluated. If none of the expressions is true on any of theELSE IF
statements, statements following theELSE
statement are executed up to theEND IF
statement, and control falls out of the structure. - If none of the expressions on the
DO IF
statement or theELSE IF
statements is true and there is noELSE
statement, control passes to the first statement following theEND IF
for that structure.