PHP for Loop Last Updated : 25 Aug, 2022 Comments Improve Suggest changes Like Article Like Report 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 (initialization expression; test condition; update expression) { // Code to be executed } Loop Parameters: Initialization Expression: In this expression, we have to initialize the loop counter to some value. For example: $num = 1;Test Condition: In this expression, we have to test the condition. If the condition evaluates to "true" then it will execute the body of the loop and go to the update expression otherwise it will exit from the for loop. For example: $num <= 10;Update Expression: After executing the loop body, this expression increments/decrements the loop variable by some value. For example: $num += 2; Example 1: The following code shows a simple example using for loop. PHP <?php // for Loop to display numbers for( $num = 0; $num < 20; $num += 5) { echo $num . "\n"; } ?> Output0 5 10 15 Example 2: The following code shows another example of for loop. PHP <?php // for Loop to display numbers for( $num = 1; $num < 50; $num++) { if($num % 5 == 0) echo $num . "\n"; } ?> Output5 10 15 20 25 30 35 40 45 Reference: https://www.php.net/manual/en/control-structures.for.php Comment More infoAdvertise with us Next Article PHP for Loop V vkash8574 Follow Improve Article Tags : Web Technologies PHP PHP-basics Similar Reads 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 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 while Loop 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: 1 min read How to Break Foreach Loop in PHP? Breaking a foreach loop consists of terminating the execution of the loop prematurely based on a certain condition. In this article, we will explore and learn two approaches to breaking for each loop in PHP.Below are the approaches to break for each loop in PHP:Table of ContentUsing break KeywordUsi 3 min read PHP list() Function The list() function is an inbuilt function in PHP which is used to assign array values to multiple variables at a time. This function will only work on numerical arrays. When the array is assigned to multiple values, then the first element in the array is assigned to the first variable, second to th 2 min read Like