.. default-domain:: chpl .. _primers-ranges: Ranges ====== `View ranges.chpl on GitHub `_ This primer illustrates Chapel ranges and range operations. .. _primers-ranges-general: Ranges (general info) --------------------- Ranges represent sequences of integral numbers, or "indices". A range literal is defined using the ``..`` operator. The lower bound is always on the left; the upper bound is always on the right. .. code-block:: chapel writeln("Basic range r"); const r = 1..10; writeRange(r); Ranges can also be defined using an `open-interval` form using the ``..<`` operator which causes the upper bound to be omitted. For example, the range ``3..<10`` is equivalent to ``3..9``. .. code-block:: chapel writeln("Open interval range rOpen"); const rOpen = 3..<10; writeRange(rOpen); This form can be convenient when iterating over a 0-based data structure using ranges like ``lo.. 0 then "increasing" else "decreasing"); } else { // We got a more complex range, do not elaborate. } writeln(); }