Let us take the example from the
while loop lesson and see how it could be done in a for loop. The basic structure of the for loop is as follows:
for ( initialize a counter; conditional statement; increment a counter){ do this code; }
$brush_price = 5; echo ""; echo ""; echo ""; for ( $counter = 10; $counter <= 100; $counter += 10) { echo ""; } echo "| Quantity | Price |
|---|
| "; echo $counter; echo " | "; echo $brush_price * $counter; echo " |
";
Output : -
| Quantity | Price |
| 10 | 50 |
| 20 | 100 |
| 30 | 150 |
| 40 | 200 |
| 50 | 250 |
| 60 | 300 |
| 70 | 350 |
| 80 | 400 |
| 90 | 450 |
| 100 | 500 |
No comments:
Post a Comment