Download
    Interview Question     &Answer
Main Menu
PHP Loop@ Shwetank education.com
Script   For Loop in php
A for loop is used when we want to execute a block of code for certain number of times
Syntax
for(initialize counter; condition until counter is reached; increment counter)
{
//execute block of code
}
Example
<?php
for($i=0; $i<=50; $i=$i+1)
{ echo $i;
}
?>

Output : Try yourself!
Script   Nested For Loop in php
<?php
$a;
$b;
{
for($a=1;$a<=10;$a++)
{
for($b=1;$b<=$a;$b++)
{
print "*"; }
print "
"; }
}
?>

Output:
*
**
***
****
*****
******
*******
********
*********
**********


Script   For-each Loop in php
<?php
$browsers = array ("Jan", "feb", "marc");
echo "<select>";
foreach($browsers as $browser)
{
echo "<option name='$browser'>$browser</option>";
}
echo "</select>";
?>
Output:

Script   While Loop in php
<?php
$i = 1;
while ($i <= 5 )
{
echo $i . "
";
$i = $i + 1;
}
?>

Output:
1
2
3
4
5



IT  Projects Links
M-Tech Thesis
Php Project
Java Project
Asp.Net Project
Android Project
Vb .Net Project
Html Project

------------------------------- Electronics  Project
Networking
Embedded system
Telecom
Robotics
CCNA
------------------------------- Latest IT  News


Copyright 2010-2015    shwetankeducation.com
Privacy & Terms