FOR EACH/NEXT statements  

Purpose

Define a loop of program statements which can sequentially examine and act upon each member of a PowerCollection or LinkListCollection.

Syntax

FOR EACH VariantVar IN CollectionObjectVar

  [statements]

NEXT

VariantVar

A simple scalar variant variable (Local, Static, Global) which receives successive collection items at the beginning of each loop iteration.

CollectionObjectVar

A simple scalar object variable which contains a PowerCollection or a LinkListCollection.

Remarks

The FOR EACH loop allows you to examine each member of a collection in sequence, to perform needed operations with that data.  If there are no member items in the collection, the loop is skipped.

When the loop begins, the first member variant in the collection is assigned to the VariantVar.  Statements in the loop can act upon or with that data to perform whatever functions are needed.  When the NEXT statement is reached, the next member item is assigned to the VariantVar, and the loop is repeated.  This repetition continues until there are no more member items.

VariantVar contains a copy of the variant in the collection.  You can alter the value of VariantVar, but these changes do not affect the member variant in the collection.

See also

EXIT FOR, FOR/NEXT, ITERATE FOR, LINKLISTCOLLECTION, POWERCOLLECTION