Perl's for loop, or for statement is used to loop through a designated block of code until a specific condition is met. The statement is made in three parts - the initial expression, the test expression, and a re-initialization of the initial expression:
for (initial; test; re-initialization) {The initial expression is only evaluated once - at the start of the whole process. From then on, the test expression determines whether or not the code inside the block is executed. If the test evaluates to true the code is executed. If the test expression evaluates false the block of code is not executed and the program continues past the for loop.
...
}
If the code block is executed, the re-initialization of the initial expression occurs afterwards. The for loop process looks something like this when you break down each of the steps:
- Set the initial expression.
- Does the test evaluate to true? If so, continue, otherwise exit the for loop.
- Execute the code block inside the for loop.
- Reset the initial expression in some way.
- Return to step 2.
