From b2a343441c0c1a0cc1c57f5ea0321744a655129e Mon Sep 17 00:00:00 2001 From: Dana Ottaviani Date: Mon, 21 Jan 2019 13:04:17 -0500 Subject: [PATCH] Adjusted indentation and code syntax (#34819) The section titles were in the code examples and it was hard to distinguish the sections from each other. --- .../learn-about-php-loops/index.md | 184 +++++++++--------- 1 file changed, 91 insertions(+), 93 deletions(-) diff --git a/guide/english/miscellaneous/learn-about-php-loops/index.md b/guide/english/miscellaneous/learn-about-php-loops/index.md index 426e4f41ca..77a2cf2416 100644 --- a/guide/english/miscellaneous/learn-about-php-loops/index.md +++ b/guide/english/miscellaneous/learn-about-php-loops/index.md @@ -14,107 +14,105 @@ PHP works with 4 different types of loops: The `while` loop continues to excecute as long as the specified condition is true. -`php +```php +``` +Example: +```php + +``` +Output: +```php + x=1 x=2 x=3 +``` + +## Do...while loop - Example: - ```php - - ``` - ``` - Output: - x=1 x=2 x=3 - ``` +In the `do...while` loop the block of code is executed before the condition is checked. - ## Do...while loop - - In the `do...while` loop the block of code is executed before the condition is checked. - - ```php - - ``` - Example: - - ```php - +``` +Example: +```php + - ``` - ``` - Output: - x=1 x=2 x=3 x=4 - ``` + do { + echo "x=$x "; + $x++; + } while ($x < 5); +?> +``` +Output: +```php + x=1 x=2 x=3 x=4 +``` - ## For loop +## For loop - The `for` loop is used when the number of times the block is to be executed is known in advance. +The `for` loop is used when the number of times the block is to be executed is known in advance. - ```php - - ``` - Example: +```php + +``` +Example: +```php + +``` +Output: +```php + x=1 x=2 x=3 x=4 +``` - ```php - - ``` - ``` - Output: - x=1 x=2 x=3 x=4 - ``` +## Foreach loop - ## Foreach loop +The `foreach` loop helps in traversing through arrays. - The `foreach` loop helps in traversing through arrays. - - ```php - - ``` - Example: - - ```php - - ``` - ``` - Output: - One Two Three \ No newline at end of file +```php + +``` +Example +```php + +``` +Output: +```php + One Two Three +```