Monday, May 30, 2011

PHP - For Loop

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 "
QuantityPrice
"; echo $counter; echo ""; echo $brush_price * $counter; echo "
";

Output : -

QuantityPrice
1050
20100
30150
40200
50250
60300
70350
80400
90450
100500

No comments:

Post a Comment