--- title: Learn About Php Loops --- Loops are blocks of code that execute a specified number of times. Using loops reduces the number of lines of code. PHP works with 4 different types of loops: * While loop * Do...while loop * For loop * Foreach loop ## While loop The `while` loop continues to excecute as long as the specified condition is true. `php Example: ```php ``` ``` Output: x=1 x=2 x=3 ``` ## Do...while loop In the `do...while` loop the block of code is executed before the condition is checked. ```php ``` Example: ```php ``` ``` Output: x=1 x=2 x=3 x=4 ``` ## For loop The `for` loop is used when the number of times the block is to be executed is known in advance. ```php ``` Example: ```php ``` ``` Output: x=1 x=2 x=3 x=4 ``` ## Foreach loop The `foreach` loop helps in traversing through arrays. ```php ``` Example: ```php ``` ``` Output: One Two Three