The for in
construct can be used to iterate an Iterator
, a lazy value
generator (more details later). One of the easiest ways to create an iterator
is to use the range notation. a..b
will yield values from a
(inclusive) to
b
(exclusive) in steps of one.
Let's write FizzBuzz using for
instead of while
.