Like a every programming langauge, Perl has for loop to iterate an array, list or hash of elements.

Perl for loop

initialization : variable is initialized and sets intial value Condition: perl Condition that evaluates true and false. It is used to test whether loop continue or exit. increment/decrement: updated variable value by add/substract Syntax:

for( initialization; condition;increment/decrement){
    //code statements body
}

here is an example that prints the number from 1 to 10 times.

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

Another way to use range operator(…), it iterates and runs the program for range length times.

example

for (1..10) { # Really a foreach loop from 1 to 10

Here is an example infinite loop in Perl.

for(;;){
    print "Infinite Loop";
}