The
for statement executes one or more statements repeatedly within a loop for each occurrence of a multiply occurring group. The
multiple_occurring_group can be a form, roster, record, item, relation, or even a dictionary (following a
selcase function call). The multiply occurring group controls how many times the
for loop is executed. An optional logical
condition, referencing items in the group, can be supplied to restrict the cases processed by the loop.
The numeric variable
counter contains the number of the current occurrence being examined. It cannot be changed inside the loop, but it can be referenced. Its starting value is 1 and its ending value is determined by the number of occurrences of the group. It is possible to declare a variable local to the loop by adding
numeric before the
counter variable.
If the group name is a record, item, or relation, then the appropriate keyword
Record,
Item, or
Relation can be used before the name.
The
for statement should be coded outside of the group it references. In the example below, note that the code is executed in
PROC QUEST. It should not be located in
PROC PERSON_REC_EDT or in a procedure for any of the data items within the person record.