Questions about this topic? Sign up to ask in the talk tab.
Perl/Basics/Loops/For
From NetSec
Revision as of 02:58, 16 July 2012 by AlizaLorenzo (Talk | contribs) (Created page with "* A for loop has a built-in counter and stops at a pre-defined number. {{code|text=<source lang="perl">my @messages = ("Hello world!\n","I like perl!\n"); for (my $counter = 0; $...")
- A for loop has a built-in counter and stops at a pre-defined number.
my @messages = ("Hello world!\n","I like perl!\n"); for (my $counter = 0; $counter < $#array; ++$counter) { print $messages[$counter]; } |
The above code will iterate through every element in an array.
It is possible to create an infinite loop using for (;;) {...}.