repeat
Executes the given function action specified number of times.
A zero-based index of current iteration is passed as a parameter to action.
Since Kotlin
1.1Samples
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
}
Executes the given function action specified number of times.
A zero-based index of current iteration is passed as a parameter to action.
Since Kotlin
1.0Samples
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
}