Prev Up Next
Go backward to Exec Command
Go up to *COMMANDS
Go forward to Output command

Doloop command


DOLOOP <loop count> FROM <initial loop value> TO <final loop value> STEP <loop step size> {

<commands>

}


where <loop count> is a sortword, and integer or sortword values may be used to specify the loop initial, final and step values. DOLOOPs may now be nested.

The DOLOOP command allows <statements> to be executed a defined number of times with an incrementing variable. The loop will always be executed at least once since the loop count variable will be incremented at the end of each loop. This variable, if omitted, is an automatically created word named LOOP. The variable may be used freely within the loop, eg.

DOLOOP LOOP1  FROM 1  TO 8  STEP 2
    {
      ...
    NEWWORD = POSITION * LOOP1
    INC NEWWORD POSSPEC
      ...
    }

will execute the commands within curly braces for values of the word LOOP1 1,3,5 and 7.

The loop values may be negative, eg.

DOLOOP  INDEX FROM 7  TO -2  STEP -3
will execute the contained commands for values of the variable INDEX of 7,4,1 and -2.

To exit from a loop before the loop variable has reached the final loop value the IF... GOTO command should be used.

eg.

DOLOOP  FROM X1  TO X2  STEP I  {
      ...
    IF $...$
        GOTO ABCD
          ...
   }
LABEL ABCD:
     ...

support@ns.ph.liv.ac.uk

Prev Up Next