range function

List<num> range(
  1. num start, [
  2. num? stop,
  3. num step = 1
])

Generates a range of numbers from start to stop (exclusive) with step.

Implementation

List<num> range(num start, [num? stop, num step = 1]) {
  if (stop == null) {
    stop = start;
    start = 0;
  }

  final result = <num>[];
  if (step > 0) {
    for (num i = start; i < stop; i += step) {
      result.add(i);
    }
  } else if (step < 0) {
    for (num i = start; i > stop; i += step) {
      result.add(i);
    }
  }
  return result;
}