
While Loop
The While loop keeps repeating an action until an association condition returns False. It means that when a while loop started, it checks the condition, if it’s true then it executes the block of statements and then rechecks the condition and executes until the condition gets False.
Syntax
initialisation;
while(condition)
{
block of statement;
increment/decrement;
}
Sample Program
<?php | |
$num = 1; | |
while ($num<=5) | |
{ | |
echo "sushant count: $num<br>" ; | |
$num++; | |
} | |
echo "Loop end's here"; | |
?> |
Output

Sample program-2
<?php | |
$num = 1; | |
while (true) | |
{ | |
echo "sushant count: $num<br>" ; | |
$num++; | |
if($num==10) | |
break; | |
} | |
echo "<br>loop ends here"; | |
?> |
Output

Nested While Loop
When we insert a while loop under a while loop then, it is called Nested While Loop.
Syntax

Sample Program
<?php | |
$num = 1; | |
while ($num<=2) | |
{ | |
echo "sushant count: $num<br>" ; | |
$num++; | |
$val=1; /* inner while loop starts | |
while($val<=2) .................. | |
{ .................. | |
echo "value is : $val <br>"; .................. | |
$val++; .................. | |
} inner while loop ends*/ | |
} | |
?> |
Output

Do While Loop
The Do-While Loop is similar to while Loop, but the condition is checked after the loop body is executed. This ensures that the loop body is run at least once.
Syntax
initialisation
do
{
block of statements;
increment/decrement;
}while(condition);
Sample Program
<?php | |
$num = 1; | |
do | |
{ | |
echo "sushant count: $num<br>" ; | |
$num++; | |
}while($num<=4) | |
?> |
Output

Nested Do While Loop
When we insert a Do-while loop under a Do-while loop then, it is called Nested-Do-While loop.
Syntax
initialisation
do
{
block of statements;
increment/decrement;
do
{
block of statements;
increment/decrement;
}while(condition);
}while(condition);
Sample Program
<?php | |
$num = 1; | |
do | |
{ | |
echo "Outer do-while count: $num<br>"; | |
$num++; | |
$val = 1; | |
do | |
{ | |
echo "inner-do-while count: $val<br>"; | |
$val++; | |
}while ($val<=3); | |
}while ($num<=2); | |
?> |
Output





With MotoShare.in, you can book a bike instantly, enjoy doorstep delivery, and ride without worries. Perfect for travelers, professionals, and adventure enthusiasts looking for a seamless mobility solution.