For

Examples of For

The FOR command provides a looping mechanism in GT.M. A FOR command does not generate an additional level on the GT.M invocation stack.

The format of the FOR command is:

        F[OR][lvn=expr[:numexpr1[:numexpr2]][,...]]]
      

Increments and limits may be positive, negative, an integer, or a fraction. GT.M never increments a control variable "beyond" a limit. Other commands may alter a control variable within the extended scope of a FOR that it controls. When the argument includes a limit, such modification can cause the FOR argument to yield control at the start of the next iteration.

The scope of a FOR can be extended with DO or XECUTE commands.

GT.M terminates the execution of a FOR when it executes an explicit QUIT or a GOTO (or ZGOTO in GT.M) that appears on the line after the FOR. FOR commands with arguments that have increments without limits and argumentless FORs can be infinite loops. Such FORs must terminate with a QUIT or a GOTO within the immediate scope of the FOR. Also, such FORs can, but seldom, terminate by a HALT within the scope of the FOR as extended by DOs, XECUTEs, and extrinsics. FORs terminated by such commands act as "while" or "until" control mechanisms.