Range operation

Learn how to generate a sequence of values.

The range operation creates a sequence of values between two endpoints, much like a for-loop in programming languages.

Ranges have the following properties:

  • They have no gaps, so each value in the sequence is one increment away from the next value.
  • They are inclusive, which means that both the start and end values are included as part of the sequence, and the sequence cannot be empty.
  • They can be ascending or descending, depending on the order of the start and end values.

You can create ranges of integers, characters, and local dates. Ranges of other types, such as floating-point numbers and multi-character strings, are not supported.

To create a range, use the .. operator between the start and end values:

/*<start>*/ .. /*<end>*/
Try in Playground

For example, the following range generates a sequence of integers from 1 to 3:

1 .. 3 // 1, 2, 3
Try in Playground

Because ranges have direction, you can also create a descending range by reversing the start and end values:

3 .. 1 // 3, 2, 1
Try in Playground

You can also create ranges of characters, like this:

'A' .. 'C' // A, B, C
Try in Playground

In fact, you can use any Unicode character, including emojis:

'😃' .. '😆' // 😃, 😄, 😅, 😆
Try in Playground

The sequence of characters in a range is determined by their Unicode code points. Refer to the Unicode character list for more information.

Finally, you can create a range of local dates by specifying the start and end dates in the ISO 8601 format:

'2025-05-08' .. '2025-05-10' // 2025-05-08, 2025-05-09, 2025-05-10
Try in Playground

For more examples of valid date formats, see date conversion.