The downTo function

Neither the two-dots operator nor the rangeTo function can create a range in reverse order. We cannot, for example, write 5.rangeTo1 or 5..1. We can, however, use the downTo function to create a range in reverse order:

val range1 = 10.downTo(1)
for(i in range1) {
println(i)
}

val range2 = 10 downTo 1
for(i in range2) {
println(i)
}

 Both range1 and range2  consist of numbers from 10 to 1.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.159.82