From the course: Perl 5 Essential Training

Unlock the full course today

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

Iterating with for

Iterating with for - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Iterating with for

- [Voiceover] Perl's for loop comes in two forms, a traditional for loop as found in C and an iterative for loop. In this movie, we'll cover the traditional C based for loop. Here's a working copy of for.pl from chapter six of the exercise files and you'll notice that I have an array that has five strings in it and these five strings are created with the quote word operator and the strings are the words one, two, three, four and five. In this case, I'm iterating through the array using the for loop and so when I run this you'll see it lists these strings one, two, three, four and five using the say function there in the for loop. So the syntax of the for loop is borrowed directly from C. It takes three arguments and the arguments are separated by semi-colons. So you can see them here my $i = 0. That's the initializer. That's the first argument is the initializer. It initializes a variable. It's usually used to initalize a variable for the loop. It's actually just an expression that is…

Contents