Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples

FOR

Draft MDC Standard

8.2.13 For

For

[ SP ]
SP lvn = forparameter


    forparameter::=


expr
numexpr1 : numexpr2 : numexpr3
numexpr1 : numexpr2



The scope of the For command begins at the next command following the For on the same line and ends just prior to the eol on this line.

The For command with an argument specifies repeated execution of the commands within its scope for different values of the local variable lvn, under successive control of the forparameters, from left to right. Any expressions occurring in lvn, such as might occur in subscripts or indirection, are evaluated once per execution of the For command, prior to the first execution of any forparameter.

For each forparameter, control of the execution of the commands in the scope is specified as follows. (Note that A, B, and C are hidden temporary variables.)

  1. If the forparameter is of the form expr1.
    1. Set lvn = expr.
    2. Execute the commands in the scope of the For command once.
    3. Processing of this forparameter is complete.
  2. If the forparameter is of the form numexpr1 : numexpr2 : numexpr3 and numexpr2 is non-negative.
    1. Set A = numexpr1.
    2. Set B = numexpr2.
    3. Set C = numexpr3.
    4. Set lvn = A.
    5. If lvn > C, processing of this forparameter is complete.
    6. Execute the commands in the scope of the For command once.
    7. If lvn > C - B, processing of this forparameter is complete; an undefined value for lvn causes an error condition with ecode = "M15".
    8. Otherwise, set lvn = lvn + B.
    9. Go to 6.
  3. If the forparameter is of the form numexpr1 : numexpr2 : numexpr3 and numexpr2 is negative.
    1. Set A = numexpr1.
    2. Set B = numexpr2.
    3. Set C = numexpr3.
    4. Set lvn = A.
    5. If lvn < C, processing of this forparameter is complete.
    6. Execute the commands in the scope of the For command once.
    7. If lvn < C - B, processing of this forparameter is complete; an undefined value for lvn causes an error condition with ecode = "M15".
    8. Otherwise, set lvn = lvn + B.
    9. Go to 6.
  4. If the forparameter is of the form numexpr1 : numexpr2.
    1. Set A = numexpr1.
    2. Set B = numexpr2.
    3. Set lvn = A.
    4. Execute the commands in the scope of the For command once.
    5. Set lvn = lvn + B; an undefined value for lvn causes an error condition with ecode = "M15".
    6. Go to 4.

If the For command has no argument:

  1. Execute the commands in the scope of the For command once; since no lvn has been specified, it cannot be referenced.
  2. Goto a.

Note that form d. and the argumentless form specify endless loops. Termination of these loops must occur by execution of a Quit or Goto command within the scope of the For command. These two termination methods are available within the scope of a For command independent of the form of forparameter currently in control of the execution of the scope of the For command; they are described below. Note also that no forparameter to the right of one of form d. can be executed.

Note that if the scope of a For command (the outer For command) contains an inner For command, one execution of the scope of commands of the outer For command encompasses all executions of the scope of commands of the inner For command, corresponding to one complete pass through the inner For command’s forparameter list.

Execution of a Quit command within the scope of a For command has two effects.

  1. When the Quit command is executed, that particular execution of the scope of the For command is terminated at the Quit command. I.e. commands to the right of the Quit command are not executed.
  2. After the Quit command has been executed, any remaining values of the forparameter in control at the time of execution of the Quit command, and the remainder of the forparameters in the same forparameter list, will not be calculated and the commands in the scope of the For command will not be executed under their control.

In other words, execution of a Quit command causes the immediate termination of the innermost For command whose scope contains that Quit command.

Execution of an argumented Quit command within the scope of a For command causes an error condition with an ecode = "M16".

Execution of a Goto command causes the immediate termination of all For commands in the line containing the Goto command, and it transfers execution control to the point specified. Note that the execution of an argumentless Quit command within the scope of a For command does not affect the local variable environment.

Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples

Copyright © Standard Documents; 1977-2024 MUMPS Development Committee;
Copyright © Examples: 1995-2024 Ed de Moel;
Copyright © Annotations: 2003-2008 Jacquard Systems Research
Copyright © Annotations: 2008-2024 Ed de Moel.

Some specifications are "approved for inclusion in a future standard". Note that the MUMPS Development Committee cannot guarantee that such future standards will indeed be published.

This page most recently updated on 09-Jan-2024, 15:14:56.

For comments, contact Ed de Moel (demoel@jacquardsystems.com)