forEachIndexedWhile method Null safety

void forEachIndexedWhile(
  1. bool action(
    1. int index,
    2. T element
    )
)

Takes an action for each element and index as long as desired.

Calls action for each element along with the index in the iteration order. Stops iteration if action returns false.

Implementation

void forEachIndexedWhile(bool Function(int index, T element) action) {
  var index = 0;
  for (var element in this) {
    if (!action(index++, element)) break;
  }
}