for each statement
for each item in collection {
trace(item.name);
}
As with other features in Simkin, the interpreter is agnostic about the underlying object model of the application. The implementation of a collection is left to the Java or C++ classes within the application.
When the interpreter encounters the for each statement, it calls the createIterator method on the underlying skExecutable class (C++) or Executable interface (Java).
This function should return a new class which is an instance of a class derived from the skExecutableIterator class (C++), or implementing the ExecutableIterator interface (Java).
The for each statement has two forms:
for each person in group {
trace(person.name);
}
createIterator function. You can interpreter this in any way you choose. e.g.:
for each Manager employee in company {
trace(employee.name);
}
createIterator method returns an iterator object, the Interpreter repeatedly calls the next method on the iterator until false is returned.
When the iteration is completed, the Interpreter will use delete to destroy the iterator.