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
Example of Do while loop.
An example program to demonstrate the Do while loop.
echo"value is :$x<br>";
value is: 7
Code in PHP
Php opening tag.
Variable is declared and initialized with value 7.
Starting with doing while loop.
Starting bracket of the loop.
echo “value is :$x<br>”;
Statements within loop that will executes.
Value of variable is incremented by 1 and loop will repeats the execution of statements untill the loop remains true.