repeat

fun repeat(times: Int, body: Lambda): Iterable<Any>

Repeats content N times. This is shorthand for .foreach {..N}.

The current index (starting from 1) can be accessed via the lambda argument.

.repeat {5}
index:
Iteration number .index

In implicit form:

.repeat {5}
Iteration number .1

As with foreach, the output is a mapping from [1, N] to another collection of values. See foreach's documentation for further details.

Return

a collection that contains the output of each iteration

Parameters

times

number of times to repeat the content

body

the output of each iteration. Accepts 1 parameter (the current repetition index, starting from 1).

Wiki page

Loops