...
/Looping Directives: while and until
Looping Directives: while and until
Learn about the while and until looping directives.
The while
directive
A while
loop continues until the loop conditional expression evaluates to a false value. Here’s an idiomatic infinite loop:
Press + to interact
while (1) {# ...}
Unlike the iteration foreach
-style loop, the while
loop’s condition has no side
effects. If @values
has one or more elements, this code is also an infinite loop, because every iteration will evaluate @values
in scalar context to a non-zero
value and iteration will continue:
Press + to interact
my @values = (0, 1, 2, 3, 4);while (@values) {say $values[0];}
To prevent such an infinite while
loop, use a destructive update of the @values
array by modifying the array ...