downTo
Returns a progression from this value down to and including the specified to value with the step -1.
The to value should be less than or equal to this
value. If the to value is greater than this
value the returned progression is empty.
Since Kotlin
1.0Samples
import java.sql.Date
import kotlin.test.assertFalse
import kotlin.test.assertTrue
fun main() {
//sampleStart
val descendingProgression = 5 downTo 1
println(descendingProgression.toList()) // [5, 4, 3, 2, 1]
val singleElementProgression = 5 downTo 5
println(singleElementProgression.toList()) // [5]
val emptyProgression = 5 downTo 7
println(emptyProgression.toList()) // []
for (i in 3 downTo 0) {
if (i > 0) println("$i...") else println("Launch!")
}
//sampleEnd
}
Returns a progression from this value down to and including the specified to value with the step -1.
The to value should be less than or equal to this
value. If the to value is greater than this
value the returned progression is empty.
Since Kotlin
1.5Samples
import java.sql.Date
import kotlin.test.assertFalse
import kotlin.test.assertTrue
fun main() {
//sampleStart
val descendingProgression = 5 downTo 1
println(descendingProgression.toList()) // [5, 4, 3, 2, 1]
val singleElementProgression = 5 downTo 5
println(singleElementProgression.toList()) // [5]
val emptyProgression = 5 downTo 7
println(emptyProgression.toList()) // []
for (i in 3 downTo 0) {
if (i > 0) println("$i...") else println("Launch!")
}
//sampleEnd
}