rangeTo method

IntRange rangeTo(
  1. int endInclusive
)

Creates a IntRange with a step count of 1

5.rangeTo(10).forEach(print);
// 5, 6, 7, 8, 9, 10

IntRanges also work downwards

10.rangeTo(5).forEach(print);
// 10, 9, 8, 7, 6, 5

The step size can be customized but is required to be positive

5.rangeTo(10).step(2).forEach(print);
// 5, 7, 9
10.rangeTo(5).step(2).forEach(print);
// 10, 8, 6

Implementation

IntRange rangeTo(int endInclusive) => IntRange(this, endInclusive);