Range[A: (Real[A] val & Number)]¶
A bounded numeric sequence with a given step size. Two named constructors control whether the far bound is included:
Range.till— excludes the far boundRange.through— includes the far bound
Direction is inferred: when from < to the range ascends, when from > to
it descends. Step is always a positive magnitude.
A zero or negative step, or a non-finite float argument (NaN or infinity), produces an empty range.
// 0, 1, 2, 3, 4
for i in Range[USize].till(0, 5) do
env.out.print(i.string())
end
// 5, 4, 3, 2, 1, 0
for i in Range[I32].through(5, 0) do
env.out.print(i.string())
end
// with a step size
for i in Range[USize].till(0, 10, 2) do
env.out.print(i.string()) // 0, 2, 4, 6, 8
end
Implements¶
- Iterator[A] ref
Constructors¶
through¶
Inclusive of the far bound.
Range.through(0, 3) yields 0, 1, 2, 3.
Range.through(3, 0) yields 3, 2, 1, 0.
Range.through(5, 5) yields 5.
Range.through(0, 9, 3) yields 0, 3, 6, 9.
Range.through(0, 10, 3) yields 0, 3, 6, 9 — the step skips the far bound.
Parameters¶
- from: A
- to: A
- step: A = 1
Returns¶
- Range[A] ref^
till¶
Exclusive of the far bound.
Range.till(0, 3) yields 0, 1, 2.
Range.till(3, 0) yields 3, 2, 1.
Range.till(5, 5) yields nothing.
Parameters¶
- from: A
- to: A
- step: A = 1
Returns¶
- Range[A] ref^
Public Functions¶
has_next¶
True while there are values remaining in the sequence.
Returns¶
- Bool val
next¶
Return the current value and advance. Errors when exhausted.
Returns¶
- A ?
rewind¶
Reset the iterator to its starting position.
Returns¶
- None val