Repetitive tasks are always a burden to us.
These repetitive tasks can be make easy by loop.
The idea of a loop is to do something over and over again until the task has been completed.
The function of the while loop is to do a task over and over as long as the specified conditional statement is true.
Here is the basic structure of a PHP while loop:
This isn't valid PHP code, but it displays how the while loop is structured.
Now study the example shown below.
Quantity | Price |
---|---|
10 | 50 |
20 | 100 |
30 | 150 |
40 | 200 |
50 | 250 |
60 | 300 |
70 | 350 |
80 | 400 |
90 | 450 |
100 | 500 |
Wonderful isn't?
If you change the while($counter <= 100) to while($counter <= 1000) a 100 row table will be produced in a blink.
The loop created a new table row and its respective entries for each quantity, until our counter variable grew past the size of 100.
When it grew past 100 our conditional statement failed and the loop stopped.
Let's see what is going on.
With proper use of loops you can complete large tasks with ease.
Note For more detail please see Php Manual at http://www.php.net