The step function helps us to create a modified range from a range that has already been created:
val range1 = 1..10
val newRange = range1.step(2)
for(i in newRange) {
println(i)
}
In this example, step(2) will skip every second element of the list. The preceding range, range1, will return a range of odd numbers. Similarly, range2 will return a range of even numbers:
val range2 = 10 downTo 1
val evenRange = range2 step 2
for(i in evenRange) {
println(i)
}