Skip to content
← Index | Lesson 2 of 5

Infinite Ranges

Infinite Ranges with take

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

Search Zolo

9 results

enespt-br