Basically, while loop executes the statement until some condition become true. This loop executes one or more statements while the given condition remains true. It is useful when number of iteration (cycle) is not known in advance.
while(condition)
statement;
First of all, the condition is evaluated. If it is true , the control enters the body of the loop and executes all statements in the body. After execution the statements, it again moves to the start of the loop and evaluates the condition again. This process continues as long as the condition remains true.
Write a sentence "Princes of courtesy, merciful, proud and strong." 3 times using while loop.
<?php
$num = 1;
while($num<=3)
{
echo "Princes of courtesy, merciful, proud and strong."."<br>";
$num++;
}
?>
Output:
Princes of courtesy, merciful, proud and strong.
Princes of courtesy, merciful, proud and strong.
Princes of courtesy, merciful, proud and strong.