W3cubDocs

/Kotlin

repeat

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
inline fun repeat(times: Int, action: (Int) -> Unit)

Executes the given function action specified number of times.

A zero-based index of current iteration is passed as a parameter to action.



fun main(args: Array<String>) {
//sampleStart
// greets three times
repeat(3) {
    println("Hello")
}

repeat(0) {
    error("We should not get here!")
}
//sampleEnd
}

© 2010–2019 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/repeat.html