Navigation
Synopsis Numeric range of values.
Syntax
  • [ Exp1 .. Exp3 ]
  • [ Exp1, Exp2 .. Exp3 ]
Description Ranges are a shorthand for describing lists of integers from Exp1 up to (exclusive) Exp3 with increments of 1. When Exp2 is present it is taken as the second element of the list and Exp2 - Exp1 is used as increment for the subsequent list elements.

A range with integer expressions is identical to a list Slice. However, a range may also contain numeric expressions that are not integers.
Examples
rascal>[1 .. 10];
list[int]: [1,2,3,4,5,6,7,8,9]
rascal>[1, 3 .. 10];
list[int]: [1,3,5,7,9]
rascal>[0.5, 3.2 .. 10];
list[real]: [0.5,3.2,5.9,8.6]
rascal>[1, -2 .. -10];
list[int]: [1,-2,-5,-8]
Benefits Ranges are mostly used to loop over ranges of integers.
Pitfalls In some cases ranges are empty where one could have expected at least one element:
rascal>[1, 3 .. -10];
list[int]: []
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.