You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a trait named Iterator that enables iteration over arbitrary sequences. Also consider adding Iterable trait to be implemented by collections with a single iter method that returns a new Iterator.
As the main consumer of these traits, add a for loop syntax. for loops require an Iterable value. They create a new variable visible inside the loop body that takes on consequent values returned by the created Iterator.
The syntax for for loops could look like this:
var v = [1, 2, 3];
for (x in v) {
writeln x;
}
v must implement Iterable, and the type of x is inferred from this implementation.
The text was updated successfully, but these errors were encountered:
Add a trait named
Iterator
that enables iteration over arbitrary sequences. Also consider addingIterable
trait to be implemented by collections with a singleiter
method that returns a newIterator
.As the main consumer of these traits, add a
for
loop syntax.for
loops require anIterable
value. They create a new variable visible inside the loop body that takes on consequent values returned by the createdIterator
.The syntax for
for
loops could look like this:v
must implementIterable
, and the type ofx
is inferred from this implementation.The text was updated successfully, but these errors were encountered: