PHP Tutorial – do while loop

The do while loop

In do while loop the statements or conditions are executed first then that condition is evaluated, the loop will continue while the condition is true.


code to be executed;
while (condition);


echo "The number is " . $num . "<br />";
while ($num<=10);


The number is 2
The number is 3
The number is 4
The number is 5
The number is 6
The number is 7
The number is 8
The number is 9
The number is 10
The number is 11

In our example we have declared a variable $num and assigned a value of 1. It will then increment by 1 and writes some output. The condition is evaluated and the loop will continue as long $num is less than o equal to ten.

, , , , , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.