php for

In php the basic structure of a for loop is

for( expression1; condition; expression2)

  • expression1 is executed once at the start. Here, you usually set the initial value of a counter
  • The condition expression is tested before each iteration. If the expression returns false, iteration stops. Here, you usually test the counter against a limit
  • expression2 is executed at the end of each iteration. Here, you usually adjust the value of the counter
  • expression3 is executed once per iteration. This expression is usually a block of code and contains the bulk of the loop code

Example of for loop

for ($distance = 50; $distance <= 250; $distance += 50) {
 echo "<tr>
<td style=\"text-align: right;\">".$distance."</td>
<td style=\"text-align: right;\">".($distance / 10)."</td>

Leave a Comment