PHP while Loop Last Updated : 22 Aug, 2022 Comments Improve Suggest changes Like Article Like Report The while loop is the simple loop that executes nested statements repeatedly while the expression value is true. The expression is checked every time at the beginning of the loop, and if the expression evaluates to true then the loop is executed otherwise loop is terminated. Flowchart of While Loop: Syntax: while (if the condition is true) { // Code is executed } Example 1: This example uses a while loop to display numbers. PHP <?php // Declare a number $num = 10; // While Loop while ($num < 20) { echo $num . "\n"; $num += 2; } ?> Output10 12 14 16 18 while-endWhile loop: Syntax: while (if the condition is true): // Code is executed ... endwhile; Example 2: This example uses while and endwhile to display the numbers. PHP <?php // Declare a number $num = 10; // While Loop while ($num < 20): echo $num . "\n"; $num += 2; endwhile; ?> Output10 12 14 16 18 Reference: https://www.php.net/manual/en/control-structures.while.php Comment More infoAdvertise with us V vkash8574 Follow Improve Article Tags : Web Technologies PHP PHP-basics Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like