From the course: Perl 5 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Loops with while and until

Loops with while and until - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Loops with while and until

- [Voiceover] The while loop is the simplest form of loop. Here's a working copy of while.pl from Chapter 6 of the exercise files. In this case, the while loop is very simple. The while keyword is followed by a logical condition in parentheses, which is followed by a block of code, which is the body of the loop. The condition is evaluated and if it's True, the body of the loop is executed, and once the body has run, the condition is evaluated again, and if it's still True, the body is executed again. This continues until the condition evaluates to False. In this case, we have an array here with five elements using the quote words operator. I've initialized the array with five strings, to the words one, two, three, four, and five, and then the condition of the while loop is the array. In logical context, the array evaluates True when the array is not empty, and it evaluates False when the array is empty. So each time through the loop, one element of the array is removed with the shift…

Contents