All exams are online now due to COVID related precautions | Download the app or write to us at

Certified PHP Developer Learning Resources Do while

Do while

The Do...While statements are similar to While statements, except that the condition is tested at the end of each iteration, rather than at the beginning. This means that the Do...While loop is guaranteed to run at least once. The Do...While loop syntax is as follows:
   code to be exected;
while (condition);

The example below will increment the value of i at least once, and it will continue incrementing the variable i as long as it has a value of less than or equal to 10:
$i = 0;
do {
   echo "The number is ".$i."
while ($i <= 10);