Lesson 6 of 15
While / Until
While Loops
A while loop runs as long as its condition is true:
my $i = 1;
while ($i <= 5) {
say $i;
$i++;
}
Until Loops
until is the opposite of while -- it runs until the condition becomes true:
my $count = 0;
until ($count == 3) {
say $count;
$count++;
}
Increment / Decrement
$x++; # increment by 1
$x--; # decrement by 1
$x += 5; # add 5
Your Task
Print the numbers 1 through 5, each on its own line, using a while loop.
JS Transpiler loading...
Loading...
Click "Run" to execute your code.