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 IFstatement marks the beginning of the structure, and theEND IFstatement marks its end. - The
ELSE IFstatement is optional and can be repeated as many times as desired within the structure. - The
ELSEstatement is optional. It can be used only once and must follow anyELSE IFstatements. - The
END IFstatement must follow anyELSE IFandELSEstatements. - The
DO IFandELSE IFstatements 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 IFstatement is true, the statements immediately following theDO IFare executed up to the nextELSE IForELSEin the structure. Control then passes to the first statement following theEND IFfor that structure. - If the expression on the
DO IFstatement is false, control passes to the firstELSE IF, where the logical expression is evaluated. If this expression is true, statements following theELSE IFare executed up to the nextELSE IForELSEstatement, and control passes to the first statement following theEND IFfor that structure. - If the expressions on the
DO IFand the firstELSE IFstatements 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 IFstatements, statements following theELSEstatement are executed up to theEND IFstatement, and control falls out of the structure. - If none of the expressions on the
DO IFstatement or theELSE IFstatements is true and there is noELSEstatement, control passes to the first statement following theEND IFfor that structure.