PHP while loop

      No Comments on PHP while loop

PHP while loop execute a block of code while the specified condition is true.


while (condition is true)
    code to be executed;


$w = 1;
while($w <= 5)
    echo "The number is: $x <br>";

The number is 1
The number is 2
The number is 3
The number is 4
The number is 5

Variable $w is set to 1. The condition is checked , and the while loop executes till $x is less than 5.The variable $w is incremented by 1, every time the loop runs.

Another Example:

echo "2 *".$x."=".2*$x;

Leave a Reply

Your email address will not be published. Required fields are marked *