Loop Statement – For
The for statement on the other hand is used for loops that have a defined number of repetitions. The “for” statement requires three parameters; the initialization of a variable that would be incremented, the condition that is to be satisfied and the number of times the block of code is to be executed. If more than one variable is needed for the increment parameter and initialization, they should be separated by a comma. The condition must evaluate as either true or false.
Syntax:
for ($a=1; $a<=5; $a++)
{
echo "Hello World!
“;
}
?>
The sample code would result in a display of the “Hello World!” statement for 5 times.
Filed under: Basic Programming, Sample Code by Avatar
