This is the documentation for the development version. There are no official binaries for it; build it from the source code in git. Download links on these pages work only after the release. For the current release, see version 7.0.

Range

Class representing a range that has start and end indexes and step size.

All instance attributes are read-only. If all arguments are integers, the range produces integer values; otherwise it produces floating-point values. step defaults to 1.

With a positive step, values increase from start while they are less than end; with a negative step, they decrease while they are greater than end. A range whose start is already past end in the step direction, or whose step is zero, produces no values.

Instance attributes

start ⇒ Number

Range start (inclusive).

end ⇒ Number

Range end (exclusive).

step ⇒ Number

Step size.

Constructors

Range(end)
range(end)

Creates new Range object with range from 0 till end.

Range(start, end)
range(start, end)

Creates new Range object with range from start till end.

Range(start, end, step)
range(start, end, step)

Creates new Range object with range from start till end with step size step.

Examples

Loop from 0 till 9
a = [];
for (i : range(0, 10)) a.append(i);
println(a); // Will print "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
Count down from 10 till 1
a = [];
for (i : range(10, 0, -1)) a.append(i);
println(a); // Will print "[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]"