repeat
Начиная с Kotlin: 1.0
inline fun repeat(times: Int, action: (Int) -> Unit)
Выполняет указанную функцию action заданное количество раз.
В функцию action в качестве параметра передаётся индекс текущей итерации, начиная с нуля.
Если параметр times отрицательный или равен нулю, функция action не вызывается.
Примеры
fun main() {
//sampleStart
// greets three times
repeat(3) {
println("Hello")
}
// greets with an index
repeat(3) { index ->
println("Hello with index $index")
}
repeat(0) {
error("We should not get here!")
}
//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/repeat.html