For each … Next Statement

 

For  Each  element in group

            [statements]

                        [Exit For]

                        [statements]

Next [element]

 

Repeats the group of statments for each element in an array of a collection.  For each … Next statements can be nested if each loop element is unique.  The For Each…Next statement cannot be used with and array of user defined types.

 

Example: 

 

Sub Main

  dim z(1 to 4) as double

  z(1) = 1.11

  z(2) = 2.22

  z(3) = 3.33

  For Each v In z

    Print v

  Next v

End Sub