[Kotlin] repeat

강다빈·2024년 7월 12일

코틀린 docs

repeat

inline fun repeat(times: Int, action: (Int) -> Unit)

주어진 함수 actiontimes 만큼 반복한다.

 // 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!")
}
profile
SKT DEVOCEAN YOUNG 2기, Kubernetes Korea Group

0개의 댓글