PHP Do While Loop
- Hi guys, In this tutorial, we will learn do-while loop statement to execute a code block repeatedly based on a condition checked at the end of each iteration using php.
- This loop is used when position looping is performed after executing statements within the loop. This means that do-while would execute its statements at least once, even if the condition fails for the first time itself.
Php do while It is also called an exit-controlled loop.
PHP Syntax
<?php
do{
code to be executed;
} while (condition);
?>
PHP Example
Edit it yourself
<!DOCTYPE html>
<html>
<body>
<?php
$i = 1;
do{
echo "The number is: $i <br>";
$i++;
}while($i <= 5);
?>
</body>
</html>