Syntax :-
while ( conditional statement is true){ //do this code; }
This isn't valid PHP code, but it displays how the while loop is structured. Here is the break down of how a while loop functions when your script is executing:
- The conditional statement is checked. If it is true, then (2) occurs. If it is false, then (4) occurs.
- The code within the while loop is executed.
- The process starts again at (1). Effectively "looping" back.
- If the conditional statement is false, then the code within is not executed and there is no more looping. The code following the while loop is then executed like normal.
$brush_price = 5;
$counter = 10;
echo "";
echo "";
echo "";
while ( $counter <= 100 )
{ echo ""; $counter = $counter + 10; } 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