Perl for Loop
Perl for loop is also known as C-style for loop. The for loop iterates the statement or a part of the program several times.
It has three parameters:
The syntax of for loop in Perl language is given below:
Flowchart of for loop in Perl
Perl for loop Example:
Let's see the simple program of for loop that prints table of 1.
1 2 3 4 5 6 7 8 9 10
Perl Nested for Loop
In this example, one for loop is nested inside another for loop. Inner loop is executed completely while outer loop is executed only once. It means if loop is running for 3 times, outer loop will execute 3 times but inner loop will execute 9 times.
1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3
Perl Infinite for Loop
If double semicolon (;;) is used in for loop, the loop will execute for infinite times. You can stop the execution using ctrl + c.
Infinite For Loop Infinite For Loop Infinite For Loop Infinite For Loop Infinite For Loop Ctrl+c