SplitScript reference / Language / range

range

syntax

start..<end | start..=end | T..<T | T..=T

Describes an explicitly exclusive or inclusive integer interval.

..< excludes the upper endpoint and ..= includes the upper endpoint. Bare .. is rejected as a range so endpoint inclusion never depends on remembered language convention; inside an array pattern, it is the separate array rest pattern syntax. In an expression, the bounds create a first-class range value; the corresponding type repeats its bound type around the same operator. In a match pattern, integer literal bounds test that interval directly and may be combined with |. Both bounds and the matched value have one exact Integer type. Empty or reversed range patterns are errors, while reversed range values are empty. Direct for iteration does not allocate a range object; storing or passing the range preserves it as an immutable value.

Examples

Exclude the upper endpoint

for index in 0u32..<3 {
    print(index)
}

Pass an inclusive range as a value

fn visit(checkpoints: u8..=u8) {
    for checkpoint in checkpoints {
        print(checkpoint)
    }
}

visit(1u8..=3)

Match an integer interval

return match level {
    0..<10 => "early",
    10..=20 => "late",
    _ => "outside",
}