Building Ranges
Generate number sequences.
What Is a Range?
A range represents an ordered sequence of evenly spaced integers, like 1, 2, 3, 4, 5.
Ranges are memory efficient because they store only the start, end, and step, not every number. They are ideal for counting and looping.
The to Keyword
The simplest range uses to, which includes both endpoints.
So 1 to 5 covers 1, 2, 3, 4, and 5. The final number is part of the range.
val r = 1 to 5
println(r)All lessons in this course
- Creating Tuples
- Destructuring Tuples
- Building Ranges
- Ranges in Loops