0Pricing
Scala for Backend Engineering & Functional Programming · Lesson

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

  1. Creating Tuples
  2. Destructuring Tuples
  3. Building Ranges
  4. Ranges in Loops
← Back to Scala for Backend Engineering & Functional Programming