Ranges in Loops
Iterate with to and until.
Looping with Ranges
Ranges and loops are a natural pair. A range gives you a tidy sequence of numbers to iterate over.
This lesson shows how to drive for loops, filter values, and build results using ranges.
A Basic for Loop
The classic counting loop uses a range with for.
The variable i takes each value of the range in turn. Here it prints 1 through 5 on separate lines.
for (i <- 1 to 5) println(i)All lessons in this course
- Creating Tuples
- Destructuring Tuples
- Building Ranges
- Ranges in Loops