Repeats
a group of statements for each element in an
array or
collection.
Synopsis
For Each element In group
[statements]
[Exit For]
[statements]
Next [element]
The
For Each block is entered if there is at least
one element in group. Once the loop has been entered, all the statements in
the loop are executed for the first element in group. As long as there are
more elements in group, the statements in the loop continue to execute for
each element. When there are no more elements in group, the loop is exited
and execution continues with the statement following the
Next statement.
The
Exit For can only be used within a
For
Each...Next or
For...Next control structure
to provide an alternate way to exit. Any number of
Exit For statements
may be placed anywhere in the loop. The
Exit For is often
used with the evaluation of some condition (for example,
If...Then),
and transfers control to the statement immediately following
Next.
Erase ^RandomData
' Generate some random nodes
For i = 65 to 90
If Rnd(i) > .5 Then
^RandomData(Chr(i),"subnode")="data"
Else
^RandomData(Chr(i))="data"
End If
Next
PrintLn "Traverse forwards"
For each k1 in ^RandomData
PrintLn k1
For each k2 in ^RandomData(k1)
Print k1,vbTAB,k2
If Exists(^RandomData(k1,k2)) and vbHasValue Then
Print " = ",^RandomData(k1,k2)
End If
PrintLn
Next
Next
If you omit element in a
Next statement, execution
continues as if you had included it. If a
Next statement
is encountered before its corresponding
For statement,
an error occurs.