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 the END 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 any ELSE IF statements.
  • The END IF statement must follow any ELSE IF and ELSE statements.
  • The DO IF and ELSE IF statements must contain a logical expression, normally one involving the relational operators EQ, 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 the DO IF are executed up to the next ELSE IF or ELSE in the structure. Control then passes to the first statement following the END IF for that structure.
  • If the expression on the DO IF statement is false, control passes to the first ELSE IF, where the logical expression is evaluated. If this expression is true, statements following the ELSE IF are executed up to the next ELSE IF or ELSE statement, and control passes to the first statement following the END IF for that structure.
  • If the expressions on the DO IF and the first ELSE IF statements are both false, control passes to the next ELSE IF, where that logical expression is evaluated. If none of the expressions is true on any of the ELSE IF statements, statements following the ELSE statement are executed up to the END IF statement, and control falls out of the structure.
  • If none of the expressions on the DO IF statement or the ELSE IF statements is true and there is no ELSE statement, control passes to the first statement following the END IF for that structure.