Course of Raku / Essentials / Loops

Using while

The while construct has a Boolean condition and a code block. Raku executes the code block repeatedly while the condition is True.

my $x = 0;
while $x <= 10 {
    $x = prompt 'Enter a number, which is not bigger than 10: ';
    say "You entered $x.";
}
say "$x is bigger than 10.";

The program asks to enter a number, and if the number is not bigger than 10, the loop body repeats. As soon as the entered number breaks the condition $x <= 10, the loop ends, and the next line of the program is executed.

$ raku t.raku
Enter a number, which is not bigger than 10: 10
You entered 10.
Enter a number, which is not bigger than 10: 4
You entered 4.
Enter a number, which is not bigger than 10: 1
You entered 1.
Enter a number, which is not bigger than 10: 20
You entered 20.
20 is bigger than 10.

Practice

Complete the quiz that covers the contents of this topic.

Course navigation

Loops   |   Loops / Using until


💪 Or jump directly to the exercises to this section.

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