PHP Examples - Loops
While, Do While, For, Foreach
Program:
<html > <head> <title>PHP Example 3 : Loops</title> </head> <body> <?php echo "PHP Example 3"; echo"<br/>"; // line break echo"<h1>"; echo"LOOPS"; echo"</h1>"; echo"<br/><li>"; echo"WHILE LOOP: PRIME NUMBERS: "; echo"<br/>"; $i=2; while($i<50) { $flag=true; $j=2; while($j<($i/2)) if($i%$j==0) { $flag=false; break; } else $j++; if($flag) echo $i.' '; $i++; } echo"<br/></li>"; echo"<br/><li>"; echo"FOR LOOP: FIBONACCI NUMBERS"; echo"<br/>"; $t1=1; $t2=1; echo $t1.' '.$t2; for($i=1;$i<10;$i++) { $t3=$t1+$t2; $t1=$t2; $t2=$t3; echo ' '.$t3; } echo"<br/></li>"; echo"<br/><li>"; echo"DO WHILE LOOP: NATURAL NUMBERS "; echo"<br/>"; $i=1; do{ echo " $i"; $i++; }while($i<=10); echo"<br/></li>"; echo"<br/><li>"; echo"FOR EACH LOOP: STUDENTS & MARKS "; echo"<br/>"; $mark["Mithun"]= "40"; $mark["Shibin"]= "38"; $mark["Manzoor"]= "35"; $mark["Suhail"]= "45"; $mark["Jishnu"]="36"; foreach( $mark as $key => $value) { echo "Name: $key, Marks: $value <br/>"; } echo"<br/></li>"; echo "<br/><b>"; echo"WWW.2K8618.BLOGSPOT.COM"; echo"</b>"; ?> </body> </html>
0 comments:
Post a Comment