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.

Loop control statements

Loop control statements - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Loop control statements

- [Voiceover] Perl provides a number of loop control statements which may be used to modify the behavior of a loop. Here's a working copy of control.pl from chapter six of the exercise files, and you notice we have a simple while loop, and it uses the shift function to take an element off of the array and then it uses say to display it. Very simple. We have the same array we've been using this chapter using quote words with five strings, one, two, three, four, and five. I've also added a variable that we're going to use, $x, a scalar variable, with the string three in it. Now, when I go ahead and run this, you see it does what we expect. It displays these five strings in order. Now, if I want to, I can skip one of these strings with the next control. I say next if $x is equal to $y, and that's the string comparison equal. And I'll go ahead and I'll run this, and you see, now it says one, two, four, five. It's skipped number three. So, what next it does is it short circuits the loop…

Contents