Using While Loops in PHP

Using While Loops in PHP


The difference between computers and humans is that computers can be told to perform the same task repeatedly without ever getting tired. To give such commands to a computer, you can use loops.

The While Loop

While Loop Script Example of a while loop script

When executed, the while loop above produces the following repetition:

While Loop Output Result of the while loop script

The Do While Loop

Do while is another technique for creating loops, with the main difference being that the conditional statement is placed at the bottom. If the previous code is converted to a do while loop, it looks like this:

Do While Script Do while script

The output will appear as follows:

Do While Output Do while used for repetition