repeat function

void repeat(
  1. int times,
  2. void action(
    1. int
    )
)

Executes the given function action specified number of times.

A zero-based index of current iteration is passed as a parameter to the action function.

If the times parameter is negative or equal to zero, the action function is not invoked.

Implementation

@pragma('vm:prefer-inline')
void repeat(int times, void Function(int) action) {
  for (var i = 0; i < times; i++) {
    action(i);
  }
}