Perl | Loops (for, foreach, while, do…while, until, Nested loops)

Looping in programming languages is a feature which facilitates the execution of a set of instructions or functions repeatedly while some condition evaluates to true. Loops make the programmers task simpler. Perl provides the different types of loop to handle the condition based situation in the program. The loops in Perl are :

“for” loop provides a concise way of writing the loop structure. Unlike a while loop, a for statement consumes the initialization, condition and increment/decrement in one line thereby providing a shorter, easy to debug structure of looping.
Syntax:

for (init statement; condition; increment/decrement )

Flow Chart:

A for loop works on a predefined flow of control. The flow of control can be determined by the following :

Example :