0Pricing
Kotlin Academy · Lesson

Step and downTo

Control progression.

Controlling Progressions

A plain range steps by one in increasing order. Kotlin lets you change both the step size and the direction.

The tools are step and downTo, which produce progressions.

The step Function

step changes how much the value increases each time.

0..10 step 2 yields 0, 2, 4, 6, 8, 10.

fun main() {
    val progression = 0..10 step 2
    println(progression.toList())
}

All lessons in this course

  1. Range Operators
  2. Step and downTo
  3. Ranges in Loops
  4. Char and Custom Ranges
← Back to Kotlin Academy