PHP do while loop is very similar to the while loop, but it always executes the code block at least once and furthermore as long as the condition remains true.



Syntax:

<?php 
do{ 
  code to be executed; 
} 
  while (condition); 
?>

php-do-while

Example:

<?php
$i=0;
do{
  $i++;
  echo "php do...while loop $i times"."<br>";
}
  while ($i<=5);
?>

Program Output:

PHP do...while loop 1 times

PHP do...while loop 2 times

PHP do...while loop 3 times

PHP do...while loop 4 times

PHP do...while loop 5 times

PHP do...while loop 6 times


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram