PHP for Loop Last Updated : 25 Aug, 2022 Comments Improve Suggest changes 1 Likes 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 Create Quiz Comment V vkash8574 Follow 1 Improve V vkash8574 Follow 1 Improve Article Tags : Web Technologies PHP PHP-basics Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like