Like while loop Do-while is also used to execute the block of code while the condition is true.
While loop is a entry controlled loop, but do-while is a exit controlled loop. Because in while loop it will check the condition first and execute the code if the condition is true.
But in do-while loop it will execute the block of codes present inside the “do” and then check the condition.
Syntax:
Do
{
code to be executed;
}
while (condition);
Example:
$i=1;
do
{
$i++;
echo "The number is " . $i . "
";
";
}
while ($i<=5);
?>
Output:
The number is 2
The number is 3
The number is 4
The number is 5
The number is 6
0 comments:
Post a Comment