Product Site

2.4. DO

REPETITOR:

CONDITIONAL:

DO groups instructions and optionally processes them repetitively. During repetitive execution, control variables (control1, control2, index, or item) can be stepped through some range of values.

LOOP groups instructions and processes them repetitively. LOOP behaves identically to DO, except for the simple LOOP ... END case, which is equivalent to DO FOREVER ... END.

Notes:
  1. The LABEL and COUNTER phrases can be in any order, if used. They must precede any repetitor or conditional fragment.
  2. The COUNTER phrase is only valid with a repetitive or conditional DO, it cannot be used on a simple DO group.
  3. control1, control2, index, item, and ctr must be symbols that are valid variable names.
  4. 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.
  5. The exprw or expru options, if present, can be any expression that evaluates to 1 or 0. This includes the list form of a conditional expression, which is a list of expressions separated by ",". The list of expressions is evaluated left-to-right. Each subexpression must evaluate to either 0 or 1. 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.
  6. The TO, BY, and FOR phrases can be in any order, if used, and are evaluated in the order in which they are written.
  7. The INDEX and ITEM phrases can be in any order, if used. They cannot be used more than once.
  8. 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 DO or LOOP instruction itself).
  9. The exprb option defaults to 1, if relevant.
  10. 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.
  11. The supplier can be any expression that evaluates to an object that supports a supplier method.

For more information, refer to Appendix A, Using DO and LOOP.