forlist…endfor
Defines a loop that processes all items in an indexed list.
forlist Item
{,
Index} in
SourceList
Your ProcScript
endfor
Parameters
Parameter |
Data Type |
Description |
---|---|---|
Item | String | Current list item |
Index | Number | Item number in list |
SourceList | String | Variable or field containing Uniface (Gold-separated) list |
Return Values
None
Use
Allowed in all component types.
Description
The forlist statement starts a loop that processes each item in a list. Each time the loop reaches the endfor statement, the current item number (and Index, if defined) are incremented. The loop executes the code in the block until one of the following conditions is met:
- item number
>
last item number - Index
>
last item number - A break statement is encountered
After the loop completes (after the endfor statement), the Index has the value the last item number + 1, or the last item reached before a break statement was encountered.
The Index can be altered by the code in the loop, which enables you to conditionally make changes in the loop as it executes.
The following example processes a list of strings
until it finds "Pompey"
variables string vList string vItem numeric vIndex endvariables vList = "Athens;Rome;Syracuse;Pompey;Sparta" forlist vItem, vIndex in vList if (vItem = "Pompey") putmess "Loop processing stopped on Item number: %%vIndex, Value: %%vItem" break endif putmess "Processing Item number: %%vIndex, Value: %%vItem" endfor
The resulting output looks like this:
Processing Item number: 1, Value: Athens Processing Item number: 2, Value: Rome Processing Item number: 3, Value: Syracuse Loop processing stopped on Item number: 4, Value: Pompey
Version | Change |
---|---|
9.5.01 | Introduced |