PHP Loops
Loops
having a great importance in any language.
1) If-else loop:-
1) If-else loop:-
If-else loop used for the condition checking if
condition is true then if executed otherwise else executed
Example shown below-
// loop starts
If (condition)
{
}
else
{
}
// loop ends
// Example --à loop1.php
<html>
<head></head>
<body>
<?php
$myname=”softfive”;
If($myname==”softfive”) {
echo “welcome”.””.”$myname”;
}else
echo “In else”;
// note : you can use nested
loop
?>
</body>
</html>
2) for
loop:-
syntax of for loop is
for(initialisation ;condition ; increment or decrement)
{
// code to execute
}
Example of for loop --àloop2.php
<html>
<head></head>
<body>
<?php
$myname=”5”;
for($i=0 ;$1<$myname ;$++) {
echo “softfive”.”
”.”$i”;
}
echo “for loop executed”;
?>
</body>
</html>