Collections and foreach
Collections and iterators
A collection contains multiple objects - like a ordinary array. Iterators solve the problem of storing and incrementing array indexes when accessing objects.
foreach iterator in collection
[foreach \$class in \$classes
if not \$class.IsInternal
] class [=\$class.Name];
[foreach \$i in 1 To 3
Write "// Step " & \$i & "\"
‘ Do some work
In the first line:
\$classes is the global object of all generated types. It is a collection of single class objects.
Foreach steps through all the items in \$classes, and executes the code following the instruction, up to the next statement, for each of them.
In each iteration, \$class is assigned to the next class object. You simply work with the class object instead of using, classes[i]->Name(), as you would in C++.
All collection iterators have the following additional properties:
The current index, starting with 0
true if the current object is the first of the collection (index is 0)
true if the current object is the last of the collection
The current object (this is implicit if not specified and can be left out)
[foreach \$enum in \$facet.Enumeration
if not \$enum.IsFirst