For Each
This command, introduced in VFP 5, is a variation on the traditional counted FOR loop. It lets you go through all the elements in an array or collection without having to figure out up front how many there are. Unlike a regular FOR loop, FOR EACH can handle some changes in the size of the array or collection inside the loop.
Usage |
FOR EACH uRef IN aGroup [ Commands ] [ EXIT ] [ LOOP ] ENDFOR | NEXT |
Parameter |
Value |
Meaning |
uRef |
Variable |
A variable that takes on the value of each element of the array or collection in turn. |
aGroup |
Array or Collection |
The array or collection to be processed. |
Commands |
Any Visual FoxPro commands |
The command(s) to be executed each time through the loop. |
In VFP 6 and earlier, if you use FOR EACH to process an array of strings and one of the strings has more than 255 characters, you get a "String too long to fit" error. This bug was fixed in VFP 7. |
Example |
* Get a list of all the open forms in the main VFP window and * minimize those that are maximized. ACTIVATE SCREEN FOR EACH oForm IN _SCREEN.Forms ? oForm.Caption IF oForm.WindowState = 2 oForm.WindowState = 1 ENDIF ENDFOR |
See Also |