forEachIndexed

inline fun <T> Iterable<T>.forEachIndexed(action: (Int, T) -> Unit)(source)

Calls action for each element and its zero-based index in iteration order.

Indexes start at zero. An empty iterable invokes no callbacks. Exceptions from iteration or the callback propagate to the caller. The inline callback supports non-local returns.

Receiver

elements to visit in their iteration order.

Parameters

action

action receiving the index followed by the current element.

Throws

if an element index would exceed Int.MAX_VALUE.