Skip to content
Course map | Lesson 2 of 5

Iterators · 6.2

Infinite Ranges

All lessons are open — jump whenever you need.

0.. creates an infinite range. Use Iter.take to limit:

// First 5 even numbers
let evens = 0..
    |> Iter.filter(|x| x % 2 == 0)
    |> Iter.take(5)
    |> Iter.collect()
print(evens) // [0, 2, 4, 6, 8]

Goal: Use an infinite range to get the first 5 multiples of 7.

lesson-6-2.zolo
Program output

Run the code to see the output

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br