LOOP Structures (MATRIX-END MATRIX command)

A LOOP structure in a matrix program affects the flow of control exactly as the analogous commands affect transformation program, except that missing-value considerations do not arise in a matrix program. Its syntax is as follows:

LOOP [varname=n TO m [BY k]] [IF [(]logical expression[)]

matrix statements

[BREAK]

matrix statements

END LOOP [IF [(]logical expression[)]]

The matrix statements specified between LOOP and END LOOP are executed repeatedly until one of the following conditions is met:

  • A logical expression on the IF clause of the LOOP statement is evaluated as false.
  • An index variable used on the LOOP statement passes beyond its terminal value.
  • A logical expression on the IF clause of the END LOOP statement is evaluated as true.
  • A BREAK statement is executed within the loop structure (but outside of any nested loop structures).

Note: Unlike the LOOP command (outside the matrix language), the index value of a matrix LOOP structure does not override the maximum number of loops controlled by SET MXLOOPS. You must explicitly set the MXLOOPS value to a value high enough to accommodate the index value. See the topic MXLOOPS Subcommand (SET command) for more information.