Minor syntax change (#22094)

This commit is contained in:
Alin Migea
2018-11-18 06:31:26 +02:00
committed by Tom
parent 382913ab84
commit fe1b98d71a

View File

@ -4,7 +4,7 @@ title: Loop
# PHP Loop # PHP Loop
When you need to repeat same task for many times, you can use loop instead of keep adding same code over and over again. When you need to repeat same task for many times, you can use loop instead of keep adding same code over and over again.
In PHP have following loop statements : In PHP you have the following loop statements :
- for - loop through a block of code with specific number of times. - for - loop through a block of code with specific number of times.
- while - loop through a block of code if condition is true. - while - loop through a block of code if condition is true.
- do...while - loop through a block of code one and continue loop if condition is true. - do...while - loop through a block of code one and continue loop if condition is true.
@ -16,7 +16,8 @@ Using a `break` within the loop can stop the loop execution.
Loop through a block of code with specific number of times. Loop through a block of code with specific number of times.
## Syntax ## Syntax
``` ```php
for (init counter; condition; counter increment or decrement) for (init counter; condition; counter increment or decrement)
{ {
// Code to be executed // Code to be executed
@ -49,7 +50,8 @@ for($index = 0; $index < 5; $index ++)
Loop through a block of code if condition is true. Loop through a block of code if condition is true.
## Syntax ## Syntax
``` ```php
while (condition) while (condition)
{ {
// Code to be executed // Code to be executed
@ -90,7 +92,8 @@ while ($index >= 0)
Loop through a block of code one and continue loop if condition is true. Loop through a block of code one and continue loop if condition is true.
## Syntax ## Syntax
``` ```php
do do
{ {
// Code to be executed // Code to be executed
@ -126,7 +129,7 @@ while ($index > 0);
Loop through a block of code for each value within an array. Loop through a block of code for each value within an array.
## Syntax ## Syntax
``` ```php
foreach ($array as $value) foreach ($array as $value)
{ {
// Code to be executed // Code to be executed