FOR Loops
The FOR loop structure allows you to define initialization statements, statements to execute after
each pass through the loop and a condition to test after each pass. If the condition evaluates to
true, another pass is made. Otherwise, the loop is terminated.
FOR loops can be used as an alternative to traditional loops. Functionally they do the same thing,
but FOR loops are more readable. FOR loops, like WHILE loops, do not process input
changes from the message buffer.
Syntax
Parameters
<INITIAL>- One or more statements that are executed one time before anyFOR-loop statements are executed. Each statement must be separated with a comma; this is typically aFOR-loop index initialization statement.<condition>- A condition whose value is computed before each pass. If the condition evaluates toTRUE, theFOR-loop statements are executed. If the condition evaluates toFALSE, the loop is terminated.<after pass>- One or more statements that are executed after each pass through the statements. Each statement must be separated with a comma. This is typically a statement that increments theFOR-loop index.
The number of loop executions is usually stated at the beginning of the loop, unlike WHILE and LONG_WHILE loops.
In Axcess, a typical loop may look something like this:
In NetLinx you can write the same loop with a FOR statement and clarify how the loop operates:
- By defining the loop like this, you clearly see how it is initialized and incremented.
- No errors appear if you forget to initialize the WHILE loop or counter.
- The
FORloop helps to insure proper structure.