Avatar ·

How to create a range in Kotlin that counts in reverse order (from larger to smaller)?

Hello colleagues! I recently started learning Kotlin and encountered a problem when working with ranges. I need to iterate through numbers from 10 to 1 in a for loop, that is, in reverse order. I tried writing it like this: ```kotlin for (i in 10..1) { println(i) } ``` But this code outputs nothing! I expected to see the numbers 10, 9, 8... 1, but the loop simply doesn't execute. I read the documentation and understood that `10..1` creates an empty range because the default step is +1, and the start value is greater than the end value. I tried using `downTo`: ```kotlin for (i in 10 downTo 1) { println(i) } ``` This worked! But I have a few questions: 1. Why doesn't `10..1` work, but `10 downTo 1` works? 2. Is it possible to create a range variable that stores a reverse se