while loop

PHP while loop execute a multiple statements repeatedly until while expression is true.

 

Syntax of while loop:

Following is given a general syntax of while loop in PHP:

The multiple statements inside while loop get executed only when expression is true.
These multiple statements enclosed within the curly braces or using the alternate syntax:
Initially if while condition is true then only while statements will execute otherwise they will not execute at even once.

 

Flowchart of PHP while loop

PHP-while-loop
 

Example

Output:

Or you can use while loop as following:
It will print same output as above example only we use endwhile instead curly braces { }.

Ankit Wasankar

Senior Java Developer
Java 11 | Microservices | Reactjs | SQL

Help others by sharing the content!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.