repeat

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

Calls action with each index from zero until times, or not at all for non-positive counts.

Indexes are visited in ascending order. Exceptions from action stop iteration and propagate to the caller. The inline action supports non-local returns.

repeat(3) { index -> println(index) }

Parameters

times

number of calls; zero and negative counts do nothing.

action

callback receiving the current zero-based index.