Course of Raku / Essentials / More about types / Positional data types
Subscripting ranges
A Range is a positional data type. As with arrays, you
can access its individual elements.
For example, this is how you print the third element in the sequence of items that the range generates:
my $r = 10..20;
say $r[3]; # 13It is important to realise that ranges, unlike arrays, do not necessarily keep all the values in memory.
Size
To get the size of the range, use the elems method as
you do with arrays.
my $r = 10..20;
say $r.elems; # 11Practice
Complete the quiz that covers the contents of this topic.
Course navigation
← Quiz 2 — Recognising lists | Quiz — working with ranges →
💪 Or jump directly to the exercises in this
section.
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська