>>-LOOP--+-------------+--+---------------+--+-----------------+--;--> +-LABEL--name-+ +-| repetitor |-+ +-| conditional |-+ >--+--------------------+--END--+--------+--;----------------------->< | +----------------+ | +--name--+ | V | | +---instruction--;-+-+
repetitor:
|--+-control1=expri--+-----------+--+-----------+--+------------+-+--| | +-TO--exprt-+ +-BY--exprb-+ +-FOR--exprf-+ | +-control2--OVER--collection-----------------------------------+ +-FOREVER------------------------------------------------------+ +-exprr--------------------------------------------------------+
conditional:
|--+-WHILE--exprw-+---------------------------------------------| +-UNTIL--expru-+
LOOP groups instructions and processes them repetitively. During repetitive execution, a control variable (control1 or control2) can be stepped through some range of values.
Notes:
The LABEL phrase, if used, must precede any repetitor or conditional.
The exprr, expri, exprb, exprt, and exprf options, if present, are any expressions that evaluate to a number. The exprr and exprf options are further restricted to result in a positive whole number or zero. If necessary, the numbers are rounded according to the setting of NUMERIC DIGITS.
The exprw or expru options, if present, can be any expression that evaluates to 1 or 0. This includes the list form of conditional expression supported by IF and WHEN, which is a list of expressions separated by ",". Each subexpression must evaluate to either 0 or 1. The list of expressions is evaluated left-to-right. Evaluation will stop with the first 0 result and 0 will be returned as the condition result. If all of the subexpressions evaluate to 1, then the condition result is also 1.
The TO, BY, and FOR phrases can be in any order, if used, and are evaluated in the order in which they are written.
The instruction can be any instruction, including assignments, commands, message instructions, and keyword instructions (including any of the more complex constructs such as IF, SELECT, and the LOOP instruction itself).
The subkeywords WHILE and UNTIL are reserved within a LOOP instruction in that they cannot be used as symbols in any of the expressions. Similarly, TO, BY, and FOR cannot be used in expri, exprt, exprb, or exprf. FOREVER is also reserved, but only if it immediately follows the keyword LOOP and is not followed by an equal sign.
The exprb option defaults to 1, if relevant.
The collection can be any expression that evaluates to an object that supports a MAKEARRAY method. Array and List items return an array with the items in the appropriate order, as do Streams. Tables, Stems, Directories, etc. are not ordered so the items get placed in the array in no particular order.
For more information, refer to Using DO and LOOP.