PHP Do...While Loop

The do...while loop is a variant of the while loop. It is similar to the while loop except that the condition check happens at the end of the loop. This means that the loop will always be executed at least once, even if the condition is false. The Syntax of do...while loop is as follows :
 do {
   code to be executed
 } while ( condition is true );
Example : The below code will print "Hello world!" five times.
<?php
  $count = 0;
  do {
    echo "Hello world!<br/>";
    $count++;
  } while($count < 5);
?>
Output :

Hello world!
Hello world!
Hello world!
Hello world!
Hello world!

The next example will print the table of 2 :
<?php
  $x = 2;
  $count = 1;
  do {
    echo $count*$x . "<br/>";
    $count++;
  } while($count <= 10);
?>
Output :

2
4
6
8
10
12
14
16
18
20

Next Topic :