step
Начиная с Kotlin: 1.0
infix fun IntProgression.step(step: Int): IntProgression
Возвращает прогрессию, проходящую по тому же диапазону с заданным шагом.
Примеры
import java.sql.Date
import kotlin.test.assertFalse
import kotlin.test.assertTrue
fun main() {
//sampleStart
val ascendingProgression = 1..6 step 2
val descendingProgression = 6 downTo 1 step 2
println(ascendingProgression.toList()) // [1, 3, 5]
println(descendingProgression.toList()) // [6, 4, 2]
//sampleEnd
}
infix fun LongProgression.step(step: Long): LongProgression
Возвращает прогрессию, проходящую по тому же диапазону с заданным шагом.
Примеры
import java.sql.Date
import kotlin.test.assertFalse
import kotlin.test.assertTrue
fun main() {
//sampleStart
val ascendingProgression = 1L..6L step 2L
val descendingProgression = 6L downTo 1L step 2L
println(ascendingProgression.toList()) // [1, 3, 5]
println(descendingProgression.toList()) // [6, 4, 2]
//sampleEnd
}
infix fun CharProgression.step(step: Int): CharProgression
Возвращает прогрессию, проходящую по тому же диапазону с заданным шагом.
Примеры
import java.sql.Date
import kotlin.test.assertFalse
import kotlin.test.assertTrue
fun main() {
//sampleStart
val ascendingProgression = 'a'..'f' step 2
val descendingProgression = 'f' downTo 'a' step 2
println(ascendingProgression.toList()) // [a, c, e]
println(descendingProgression.toList()) // [f, d, b]
//sampleEnd
}
infix fun UIntProgression.step(step: Int): UIntProgression
Возвращает прогрессию, проходящую по тому же диапазону с заданным шагом.
Примеры
import java.sql.Date
import kotlin.test.assertFalse
import kotlin.test.assertTrue
fun main() {
//sampleStart
val ascendingProgression = 1u..6u step 2
val descendingProgression = 6u downTo 1u step 2
println(ascendingProgression.toList()) // [1, 3, 5]
println(descendingProgression.toList()) // [6, 4, 2]
//sampleEnd
}
infix fun ULongProgression.step(step: Long): ULongProgression
Возвращает прогрессию, проходящую по тому же диапазону с заданным шагом.
Примеры
import java.sql.Date
import kotlin.test.assertFalse
import kotlin.test.assertTrue
fun main() {
//sampleStart
val ascendingProgression = 1UL..6UL step 2L
val descendingProgression = 6UL downTo 1UL step 2L
println(ascendingProgression.toList()) // [1, 3, 5]
println(descendingProgression.toList()) // [6, 4, 2]
//sampleEnd
}
© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.ranges/step.html