Course of Raku / Essentials / Loops / Exercises / Digital stairs
Solution: Digital stairs
The program uses two loops and two ranges.
Code
Here is one of the possible solutions:
my $size = prompt 'Enter the size: ';
for 1..$size -> $n {
.print for 1..$n;
print "\n";
}
🦋 Find the program in the file digital-stairs.raku.
Output
Run the program and enter the size of the structure:
$ raku exercises/loops/digital-stairs.raku
Enter the size: 7
1
12
123
1234
12345
123456
1234567
Comment
Note how the current digit is printed:
.print for 1..$n;
As with say
, the print
routine can be called as a method. In this case, it is called on the topic variable $_
.
Course navigation
← Conditional checks / Ternary operator | Data type conversion →
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська