Course of Raku / Essentials / Loops / Using while

Quiz — the while loop

1

What does this program print?

my $n = 10;
while $n {
    $n--;
}
say $n;
0 Answer: (: 0, 1, −1 :)

2

How to prevent this program from running infinitely? Make the necessary changes to the code.

. my $n = 5;
. my $a = 10;
. while $n {
n a     say $␣--;
. }

Course navigation

Loops   |   Loops / Using until


💪 Or jump directly to the exercises to this section.

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