PHP code for condition and loop like if, else if, for, while, switch
PHP code for condition and loop
Example :
<?php
$color = array("red", "orange", "white", "blue", "yellow");
foreach($color as $key=>$value) {
if ($value=="white") {
continue; //skip execution for white color
}
echo "color is $value </br>";
}
?>
<?php
$num=1;
while($num <= 5) {
if ($num==3) {
$num++;
continue;
}
echo "The number is: $num <br>";
$num++;
}
?>
<?php
for($i=0;$i<=8;$i++) {
if ($i==3) {
continue;
}
echo "The number is: $i <br>";
}
echo "Welcome to aryatechno! <br>";
?>
<?php
$num=1;
while($num <= 8) {
if ($num==4) {
break;
}
echo "The number is: $num <br>";
$num++;
}
?>
<?php
$color = array("red", "orange", "white", "blue", "yellow");
foreach($color as $key=>$value) {
if ($value=="white") {
break;
}
echo "color is $value </br>";
}
?>
<?php
$marks=60;
switch($marks){
case 50:
echo("marks is equals to 50");
break;
case 60:
echo("marks is equal to 60");
break;
case 70:
echo("marks is equal to 70");
break;
default:
echo("marks is not valid!!");
}
?>
<?php
for($i=0;$i<=8;$i++) {
if ($i==3) {
break;
}
echo "The number is: $i <br>";
}
echo "Welcome to aryatechno! <br>";
?>
<?php
$num=6;
do{
echo "The value is $num <br/>";
$num++;
}while($num<=5);
?>
<?php
$num=1;
do{
echo "The value is $num <br/>";
$num++;
}while($num<=10);
?>
<?php
$i=1;
while($i<=2){
$j=1;
while($j<=5){
echo "I:$i | J:$j<br/>";
$j++;
}
echo "-----------<br/>";
$i++;
}
?>
<?php
$num=1;
while($num <= 8) {
echo "The number is: $num <br>";
$num++;
}
?>
Output :
Comments