Spec-Zone.ru › Kotlin 1.8

repeat

kotlin-stdlib / kotlin / repeat
Требования к платформе и версии: JVM (1.0), JS (1.0), Native (1.0)
inline fun repeat(times: Int, action: (Int) -> Unit)

Выполняет заданную функцию action указанное количество раз.

Ноль-базовой индекс текущей итерации передаётся в качестве параметра функции action.



fun main(args: Array<String>) {
//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–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/repeat.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API