Do-while Loop:
Do-while loop is a control flow statement it is also called do-loop. It must run the code once and then checks the condition and repeat the loop if the condition is true otherwise terminate the loop.
Do-while Loop in PHP:
When we want to run our code at least once whatever the condition is we use do-while loop because it must execute the code one time and then checks the condition and response according to the condition. In the given code we initialize variable i with 1 and then in do block increment i and print it. This do block must execute at least once then it has to check the given condition that is if variable i is less then and equal to 5.
Syntax:
do
{
code to be executed;
}
while (condition);
Code:
<?php
$i=1;
do
{
$i++;
echo "The number is " . $i . "<br />";
}
while ($i<=5);
?>
Above is a simple code to use do-while loop in php.
This simple article tells that how we can use do-while loop in php.