FOR EACH … ENDFOR Command

Example    See Also

Executes a set of commands for each element in a Visual FoxPro array or collection.

Syntax

FOR EACH Var IN Group

   Commands

   [EXIT]

   [LOOP]

ENDFOR | NEXT [Var]

Settings

Var

A variable or array element used to iterate through the elements of Group.

Group

A Visual FoxPro array, an OLE array, a Visual FoxPro collection, or an OLE collection.

Commands

Specifies the Visual FoxPro commands to be executed for each element in Group. Commands can include any number of commands.

EXIT

Transfers control from within the FOR EACH ... ENDFOR loop to the command immediately following ENDFOR. You can place EXIT anywhere between FOR EACH and ENDFOR.

LOOP

Returns control directly back to the FOR EACH clause without executing the statements between LOOP and ENDFOR. LOOP can be placed anywhere between FOR EACH and ENDFOR.