Skip to content

Range

1 min read

Import: import system.core;

Ranges are also available without an explicit import. See Ranges for runnable examples, including descending traversal.

Range

An exclusive integer range that counts toward its end, ascending or descending.

public struct Range

start

The first value, included unless the range is empty.

public start: int

end

The stopping value, always excluded.

public end: int

constructor

Creates a range from start toward the excluded end, with unit steps.

public constructor(start: int, end: int)

length

The number of elements. Panics if the distance exceeds the maximum int (2147483647).

public get length(): int

is_empty

True when the start and end are equal.

public fun is_empty(): bool

contains

True when value occurs before the excluded end in either direction.

public fun contains(value: int): bool

iterator

Creates a fresh cursor that visits the range in unit steps toward its end.

public fun iterator(): RangeIterator