for each Statement

A for each loop lets you run a section of code for each element in a List or Set.

Syntax

for each <NEEDLE> in <HAYSTACK>
<BODY>
next

Usage

The following example prints each of three items (1, 2, 3) in a list.
dim myList = [1, 2, 3]
for each num in myList
print num
next
The exit for statement can be used to exit a for each loop early, before reaching the end of the collection. This example prints only the first two items in the list, because the exit for statement exits the loop when the loop variable num is 2.
dim myList = [1, 2, 3]
for each num in myList
print num
if num = 2 then
exit for
end if
next