Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Do while Loop in PHP

Last modified on January 7th, 2019 at 8:25 am

Do while Loop in PHP

The do while loop always executes a block of statements once, it then checks the condition and repeats the loop as long as the specified condition is true. In doing while loop the condition is checked after executing a statement. It means the do while loop will execute its statement at least once, even if the condition is false the first time.

Flowchart of Do While Loop

do while loop in php
Figure: do while loop in PHP.

Example of Do while loop.

An example program to demonstrate the Do while loop.


value is: 7


Code in PHP


<?phpPhp opening tag.
  $x=7;Variable is declared and initialized with value 7.
 doStarting with doing while loop.
 {Starting bracket of the loop.
                 echo “value is :$x<br>”;Statements within loop that will executes.
                 $x++;Value of variable is incremented  by 1 and loop will repeats the execution of statements untill the loop remains true.
 }Ending of loop
while($x<=6)Here the condtion is checked 
?>Closing tag of php.


Code in PHPSame code in C++
  $x=7;Int x=7;
                 echo “value is :$x<br>”;Cout <<”value is :”<<x<<endl;


Prof. Fazal Rehman Shamil
Researcher, Publisher of International Journal Of Software Technology & Science ISSN: 2616-5325
Instructor, SEO Expert, Web Programmer and poet.
Feel free to contact.