The for loop allows you to specify a starting
condition, an evaluation criteria, and an operation to be performed on
each loop, all within a single line of code.
The initial expression is set when the loop is
initially entered.
The test expression is evaluated at the top of each
time through the loop. As soon as the expression is found to be
false, the program skips the body of the loop and continues with the
next line of code.
The re initialization expression is executed on the
second and all successive iterations through the loop. It is
not executed the first time through the loop.
Example:
for ( initial_expression; test_expression; re-initialization_expr)
{
some_statement;
some_statement;
some_statement;
}
Example:
# Print the number 0 to 999
for ( $x=0; $x < 1000; $x++)
{
print "$x\n";
}
You can put all sorts of goofy stuff in as your initial, test,
and re-initialization expressions, and do all sorts of goofy stuff.
The most common is leaving the initialization expression completely
blank (if you already have a value for the variable and don't want to
mess with it).