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 V vkash8574 Follow Improve 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