PHP while Loop

  • Hi guys, In this tutorial we will learn how to use while Loop using PHP.
  • The while loop is used when you want to the loop to execute and continue executing while the specified condition is true.
  • While the loop is also called the entry control loop, becuse in while loop the first check condition an then executed the code.

PHP Syntax

<?php
	while(condition){
    // Code to be executed
}
?>

PHP Example

Edit it yourself

<!DOCTYPE html>
<html>
<body>

<?php
   $i = 1;
	  while($i <= 5) {
	    echo "The number is: $1 <br>";
	    $i++;
	  }
?>


</body>
</html>

Output :

Edit it yourself
  • The number is: 1
  • The number is: 2
  • The number is: 3
  • The number is: 4
  • The number is: 5
  • Previous
  • Next