====== For statement ======
The for statement is enhanced in XL. It can take two additional type of arguments: [[01_user_documentation:07_rgg_xl:02_xl:08_object:04_generator|generators]] and DisposableIterators.
===== Generators =====
When the argument of the for statement is a generator expression, the iteration is over every yielded value of the expression. Using this type of iteration, we may write:
for (int i : 0 : 100) {...}
for (Shoot s : (* Shoot *)) {...}
for ((* s:Shoot *)) {...}
===== DisposableIterator =====
If the argument of the for statement implements the interface: ''de.grogra.xl.lang.DisposableIterator'', the for loop is compiled to this equivalent:
I it = DisposableIterator;
Throwable t = null;
try {
while (it.next()) {
T i = it.value();
b
}
}
catch (Throwable u) {
t = u;
throw u;
}
finally {
it.dispose(t);
}
So the next method governs the loop, the invocation of value obtains the value for the current iteration, and the final invocation of dispose is guaranteed even in case of an exception. If //I// does not have a method value(), the disposable iterator iterates over void, then an enhanced for-statement without iteration variable has to be used.