Iteration
"for" loops
The usual way to iterate a collection is with a for loop.
A for loop is an expression. It can be void, or return an output collection.
A type annotation after the for keyword types the entire for expression.
A for loop can be squeezed onto one line using then.
for loops are a convenient syntax for calling a function named for-loop with a lambda.
If you want the collection indices too, use with-index.
for? loops work like for loops, but the body can return an option.
An empty option value will be ignored.
These call a function named for-option.
There are also for* loops, which work like for loops,
but the body returns an array that is flattened into the result.
These call a function named for-star.
Ranges
nat types are iterable too.
The number acts like a collection of all the numbers less than it.
ranges are also iterable (if the type in the range has a next function).
You can reverse most iterable things.
Iteration with early return
There is no early return from a for loop; it always iterates every element of the collection.
The most primitive iteration function is some which stops when the lambda returns true.
A more general function is first.
Here, the callback returns an option, and the first non-empty result is returned.
first works a lot like an until loop with a condition-body (see Loops);
it keeps running the body until it gets a result.
Unlike an until loop, it can also stop running if it reaches the end of the collection,
so it returns an option.