PHP while Loop Last Updated : 22 Aug, 2022 Summarize Comments Improve Suggest changes Share 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 Next Article PHP while Loop V vkash8574 Follow Improve Article Tags : Web Technologies PHP PHP-basics Similar Reads PHP do-while Loop The do-while loop is very similar to the while loop, the only difference is that the do-while loop checks the expression (condition) at the end of each iteration. In a do-while loop, the loop is executed at least once when the given expression is "false". The first iteration of the loop is executed 1 min read PHP Loops In PHP, Loops are used to repeat a block of code multiple times based on a given condition. PHP provides several types of loops to handle different scenarios, including while loops, for loops, do...while loops, and foreach loops. In this article, we will discuss the different types of loops in PHP, 4 min read PHP for Loop The for loop is the most complex loop in PHP that is used when the user knows how many times the block needs to be executed. The for loop contains the initialization expression, test condition, and update expression (expression for increment or decrement). Flowchart of for Loop: Syntax: for (initial 2 min read PHP Variables A variable in PHP is a container used to store data such as numbers, strings, arrays, or objects. The value stored in a variable can be changed or updated during the execution of the script.All variable names start with a dollar sign ($).Variables can store different data types, like integers, strin 5 min read PHP break (Single and Nested Loops) In PHP break is used to immediately terminate the loop and the program control resumes at the next statement following the loop. Method 1: Given an array the task is to run a loop and display all the values in array and terminate the loop when encounter 5. Examples: Input : array1 = array( 1, 2, 3, 2 min read Like