*FOR

<< Click to Display Table of Contents >>

Navigation:  Reference > Pre-processor >

*FOR

The *FOR command opens a loop. It instructs the Pre-processor to process the text following, down to the corresponding *END command, a variable number of times, depending on the settings of the loop parameters, and to output the text, making any necessary substitutions, each time through the loop.

The form of the *FOR command is:

[*FOR x = AE : AE ... : AE]

where x is any index not currently in use as a loop index (used as the index of a loop previously opened by a *DO or *FOR command which has not yet been closed), and the AEs specify the value x is to take each time through the loop. The number of times the loop is executed is the number of AEs specified; a maximum of 5000 iterations is allowed. So the command:

[*for lpLoop = 1:17:24]

tells the Pre-processor to process the lines following three times, with lpLoop=1, lpLoop=17 and lpLoop=24.

All loops begun with *FOR must execute at least once; the AEs may take any value and may be ordered in any way.

The loop index may not be reset (by a *SET, *DO or *FOR command) inside a loop but indices used or referenced in the loop parameters may be reset, as it is their values when the loop begins that are used in computing the parameters. At the end of the loop the index is unset automatically and may not be referenced again until it has been set again.

A loop continues until the *END command with the loop index is found, so a loop beginning [*for Region= ... ] continues until the command [*end Region] is found. Note that these two commands may appear on the same line.

Loops may be nested - a loop within a loop is allowed - up to a depth of 20, but may not overlap. Where a loop using LoopA is opened, followed by one using LoopB, then [*end LoopB] must be found before [*end LoopA]. This applies to both [*DO ... ] loops and [*FOR ... ] loops.

Examples of valid *FOR commands:

[*for lpProduct=1:17:76:41]

[*for lpWhich = Prime : Prime+3 : Prime+5 : Prime+21]