for loop in php
while (condition) {
code to be executed;
}
//Example
<?php
$i = 0;
$num = 50;
while( $i < 10) {
$num--;
$i++;
}
echo ("Loop stopped at i = $i and num = $num" );
?>
//...................................
foreach (array as value) {
code to be executed;
}
//Example
<?php
$array = array( 1, 2, 3, 4, 5);
foreach( $array as $value ) {
echo "Value is $value <br />";
}
?>
for (initialization; condition; increment){
code to be executed;
}
//Example
<?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" );
?>
//.......................................//
do {
code to be executed;
}
while (condition);
//Example
<?php
$i = 0;
$num = 0;
do {
$i++;
}
while( $i < 10 );
echo ("Loop stopped at i = $i" );
?>