PHP do-while

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

Courses
Subscribe Updates via Email

Join 49,000+ W3schools lovers and get all the latest tutorials, programs, algorithms in your inbox.