PHP While Loop

The While Loop is most basic loop in PHP. It is used to execute a specific block of code repeatedly as long as the given condition is true. In while loop the condition will checked first and If condition become true, execute a block of code executed. Syntax :
while ( condition is true ) {
  code to be executed
}
Example : The below code will print "Hello world!" five times.
<?php
  $count = 0;

  while($count < 5) {
    echo "Hello world!<br/>";
    $count++;
  }
?>
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;
  while($count <= 10) {
    echo $count*$x . "<br/>";
    $count++;
  }
?>
Output :

2
4
6
8
10
12
14
16
18
20


Next Topic :