Course of Raku / Essentials / More about types / Positional data types / Arrays

Quiz — Arrays

There is an array:

my @data = 10, 20, 30, 40, 50;

Array elements

What do the following lines print?

10say @data[0]; — (: 10, 20, 30, 40, 50 :)Don’t forget the elements are counted from 0.
40say @data[3]; — (: 10, 20, 30, 40, 50 :)The index 3 stands for the 4th element.
50say @data[4]; — (: 10, 20, 30, 40, 50 :)

Array length

What do the following statements print?

5say @data.elems; — (: 0, 1, 2, 3, 4, 5 :)
5say +@data; — (: 0, 1, 2, 3, 4, 5 :)This conversion gives the size of the array.
5say +@data.elems; — (: 0, 1, 2, 3, 4, 5 :)Casting the result of @data.elems to an integer, thus no change.

Course navigation

Arrays   |   Nested arrays

Translations of this page: EnglishDeutschEspañolItalianoLatviešuNederlandsБългарскиРусскийУкраїнська