PHP While Loop with example

PHP While Loop with example


PHP While Loop executes a block of code to be executed until the condtion is true.

Syntax :

while (condition) {
    block of code;
}

Here are following steps to execute while loop:

1.First the condition given inside the brackets after the while condition is checked.

2.If the condition is satisfied or is true, then control is moved inside the loop.

3.The statment inside the loop is executed.

4.once all the statements inside the loop are executed,the condtion is checked again,and if it is true ,the execution is continues.

5.When the condition is evaluated to be false, the control will not move inside the loop, and the while loop terminates.

 

While Loop Example:

Output : 1 

                2 

                3

                4

                5