range

range(start, end) ⇒ Range range(start, end, step) ⇒ Range range(end) ⇒ Range:: Creates a Range object for iteration.

+ .Parameters

start

Numeric

Start value (inclusive). If only one argument is provided, start defaults to 0 and the argument becomes end

end

Numeric

End value (exclusive)

step

Numeric

Step value. Optional, defaults to 1

+ The first value produced is always start, even if it is already past end. Each following value is produced while it is less than end if end is positive, or greater than end if end is zero or negative; the sign of step is not taken into account (known issue, netxms#3810). Counting down with a negative step therefore works only towards a zero or negative end, for example range(10, 0, -1).

+ .Return

Range object that is iterable and can be used in for-each loops.

+

// Create range from 0 to 9
for (i : range(10)) {
    println(i);  // prints 0, 1, 2, ..., 9
}

// Create range from 5 to 9
for (i : range(5, 10)) {
    println(i);  // prints 5, 6, 7, 8, 9
}

// Create range from 0 to 10 with step 2
for (i : range(0, 10, 2)) {
    println(i);  // prints 0, 2, 4, 6, 8
}