Perl For Loop

The Perl for loop is used to loop through a block of code until a specified condition is met. The for loop statement contains three sections followed by a block of code. Below is an example.

A Simple For Loop Example

for (my $number = 1; $number <= 10; $number++) {
  print "$number ";
}

The first section initializes a variable

my $number = 1;

Then, the loop condition is provided. The loop will run as long as this is true.

$number <= 10;

Finally, the last section is executed at the end of each loop iteration. In our example's case, $number increments by one.

$number++

Executing this loop results in:

1 2 3 4 5 6 7 8 9 10

For Loop and Arrays

Here is an example of how the for statement can be used to loop through an array.

my @languages = ("Perl", "Python", "C", "Fortran");
my $size = @languages;
for (my $i = 0; $i <= $size; $i++) {
  print "$languages[$i]\n";
}


Comments

tiffany jewelry Choose, buy

tiffany jewelry
Choose, buy and shop for on sale tiffany jewelry including Tiffany & Co Silver Necklace, Pendants, Bangles, Bracelets, Earrings, Rings and Accessories.
tiffany co
Tiffany Jewellery offering bangle Jewellery, bracelet jewelry, eardrop jewelry, necklace jewelry, ring jewelry, finger ring jewelry and earring jewelry
tiffany
tiffany and co
links of london
links london
Tiffany Style Silver Jewelry: Rings, Earrings, Necklaces, Bracelets and more Tiffany Jewellery at low prices.

Perl for loop is so good.

Perl for loop is so good. This is such a great process and works so well.
qui tam

always provide GUCCI Replica

always provide GUCCI Replica Handbags, and all kinds of replica GUCCI Handbags lower price for sale, the more fake GUCCI Handbags you choose, the cheaper price you get.
As everyone knows that the Chanel Handbags are popular in the whole world, sell replica Chanel Handbags can get more profit, many people like to sell chanel bags because fashion women love them.
Taking the Prada Handbags to join the big party can show women's fashion, so even the poor people like to buy replica Prada Handbags, so when you walk on the road, you never surprised by so much fake Prada Handbags, do you feel have a Prada replica Handbags is a cool action?
Fashion women love Miu Miu Handbgs, but the price is to high, so many ladies choose Miu Miu replica Handbgs, in the replica Miu Miu Handbgs shops, you will get the popular fake Miu Miu Handbgs that you love.

There is very, *very* rarely

There is very, *very* rarely any reason to use a C-style for loop in Perl. Your examples would be done much more easily (and with much less chance of bounds-checking errors) with:
for my $number (1..10) {
print "$number ";
}

and
my @languages = ("Perl", "Python", "C", "Fortran");
for my $language (@languages) {
print "$language\n";
}

Or, if you need the index of the language for some other purpose,
my @languages = ("Perl", "Python", "C", "Fortran");
for my $i (0..$#languages) {
print "$languages[$i]\n";
}

+1 ;)

+1 ;)