Looping Directives: while and until
Explore Perl's while and until looping directives to control flow in your programs. Understand how to write idiomatic loops, prevent infinite loops with array updates, and apply postfix forms and do blocks for complex iteration scenarios. This lesson helps you write clear and efficient looping constructs in Perl.
The while directive
A while loop continues until the loop conditional expression evaluates to a false value. Here’s an idiomatic infinite loop:
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:
To prevent such an infinite while loop, use a destructive update of the @values array by modifying the array ...