PHP While Loop

PHP While Loop tutorial explain you How to use while loop in PHP? with simple examples.

Looping permits you to run an group of statements repeatedly. Certain loops repeat statements until a condition is False; others repeat statements until a condition is True. There are additionally loops that repeat statements a particular number of times.

While Loop in PHP

The expression evaluates to true the body of loop is executed and afterward the expression is reevaluated (If it is true, the group of the loop is executed). This process until the test condition becomes false and control gets exchanged out of the loop .

Syntax on PHP While loop:

Example on PHP While loop:

 Output is:

PHP Do While Loop

PHP Do While Loop statements are similar to While statements, except that the condition is tested at the end of each iteration, rather than at the beginning. This means that the Do While loop in PHP is guaranteed to run at least once.

Syntax on Do While loop in PHP:

Example on Do While loop in PHP:

Output will be:

The example above will decrement the value of counter at least once, and it will continue decrementing the variable counter as long as it has a value of less than 0.

Previous articlePHP Arrays
Next articlePHP For Loops
I am a young Information Systems Security Engineer(CEH). I had started with penetration testing when i am 17 years old. It all started with Kali linux and Metasploit.In free time i will play with Security holes/Bug bounty/Pentesting and Hacking !!!