Course of Raku / Essentials / Variables and data types essentials
Ranges
Ranges in Raku generate lists of sequential items.
In the simplest case, a range is a list of incrementing integer
numbers. To create a range, use the .. operator and the two
values that define the minimum and maximum values of the range:
1 .. 5Spaces around the operator are optional. The following construction can be written as:
1..5While a range is a means to generate lists, it is still a single object, so it can be saved in a scalar variable:
my $r = 1 .. 5;Not only numbers
It is possible to construct a range from other data types, for which Raku knows how to increment them. For example:
my $letters = 'a' .. 'z';Ranges are objects of their own data type in Raku. The type of the
variable $r is Range.
Topics in this section
Practice
Complete the quizzes that cover the contents of this section.
Exercises
This section contains 1 exercise. Examine all the topics of this section before doing the coding practice.
Course navigation
← Quiz: Boolean values | Excluding endpoints →
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська