A for loop executes the code block for a set number of iterations. This loop has the following syntax.
<?php
for($i=0; $i<100; $i++)
{
//code block
}
?>
$i
is the counter.
The first part specifics the starting value of the counter.
The second part specifies the condition when you want the loop to stop.
The third part specifies what code you want to execute once you get execute to the bottom of the {}
section. Generally, you simply write $i++
meaning “when you hit the bottom of the section, you increase the counter by 1.”
The loop will keep iterating until the condition in the second part is met.
Example
<?php
for($i=0; $i<20; $i++)
{
echo $i;
echo "<br>";
}
?>
Result