The loop statement: for, do...while, foreach and we add break - continue statement in PHP.
PHP Tutorial » For do while foreach break continue in php
Loops in PHP are used to execute the same block of code a specified number of times. We are discussing PHP supports following four loop types: for, while, do...while, foreach.
We will discuss about continue and break keywords used to control the loops execution.
For loop in PHP statement.
Syntax
{
code to be executed;
}
Example of statement - for loop PHP-
$a = 0;
$b = 0;
for( $i = 0; $i<5; $i++ )
{
$a += 10;
$b += 5;
}
echo ("At the end of the loop a = $a and b = $b" );
?>
- While - loop PHP statement
The while statement will execute a block of code if and as long as a test expression is true.
Syntax of - While - loop PHP
{
code to be executed;
}
Example of - While - loop PHP
$num = 50;
while( $i < 10)
{
$num--;
$i++;
}
echo ("Loop stopped at i = $i and num = $num" );
- do... while - loop PHP statement
Syntax
code to be executed;
}
while (condition);
Example
$num = 0;
do {
$i++;
}
while( $i < 10 );
echo ("Loo
- foreach - loop statement PHP
Syntax
code to be executed;
}
Example - foreach - loop statement PHP
foreach( $array as $value )
{
echo "Value is $value";
}
Value is 1
Value is 2
Value is 3
Value is 4
Value is 5
- break - statement PHP
The PHP break keyword is used to terminate the execution of a loop prematurely.
Example - break - statement
while( $i < 10) {
$i++;
if( $i == 3 )break;
}
echo ("Loop stopped at i = $i" );
?>
- continue - statement PHP
Example
foreach( $array as $value ) {
if( $value == 3 )continue;
echo "Value is $value";
}
Value is 1
Value is 2
Value is 4
Value is 5
for PHP, do...while PHP, foreach PHP, break, continue statement in PHP
The loop statement: for, do...while, foreach and we add break - continue statement in PHP - php tutorial
This tool makes it easy to create, adjust, and experiment with custom colors for the web.

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

Find here examples of creative and unique website layouts.

Find here examples of creative and unique website CSS HTML menu.