PHP while loop syntax and example

While loop in PHP is also used for repeating statements in PHP.

PHP while loop check for condition if condition is true then code inside body of loop is get executed.

while – As long conditions is true, it loop back again and again through block of code.

while (condition is true) {
code to be executed;

Example: Write a program to use while loop in PHP.

The increment and decrement while loop count variable can used only inside loop.

Like here $a++ is used to increment the value of $a.

programmer has to take care of this otherwise while loop will be infinite.


The number is: 11
The number is: 12
The number is: 13