For Each ... Next (statement)

<< Click to Display Table of Contents >>

For Each ... Next (statement)

For Each Element In Group

 [Statements]

 [Exit For]

 [Statements]

Next [Element]

Executes a group of statements for all elements of a field or a collection.

Element is a variable of type Variant (for arrays) or Object (for collections) that successively takes on the values of the individual elements from Group.

For Each ... Next cannot be used with arrays of user-defined types.

See also: For Next, Exit, section Arrays, section Using collections

Example:

Sub Main

 Dim z(1 To 4) As Double

 z(1) = 1.11

 z(2) = 2.22

 z(3) = 3.33

 z(4) = 4.44

 For Each v In z

         Print v

 Next v

End Sub