How to use do-while loop in PHP

In this article, I will explain how the do-while loop can be used in PHP.
  • 2155

do-while Loop in PHP

  • The do-while statement will always execute the block of code once, it will then check the condition, and repeat the loop while the condition is true.
  • The do-while would execute its statements at least once, even if the condition fails for the first time itself.


  code to be executed;
while (condition);


The following example show the do-while loop that starts with a=1. It will then increment a with 1, and write some output. Then the condition is checked, and the loop will continue to run as long as a is less than, or equal to 5:



<h2 style="color: darkkhaki;">do-While Loop example</h2>






    echo "The number is " . $a . "<br />";


    while ($a<=5);







You may also want to read these related articles here
Ask Your Question 
Got a programming related question? You may want to post your question here
© 2020 DotNetHeaven. All rights reserved.