Loop Statements – Do While

The loop statement is used to execute a block of code at least once then repeats the process as long as a set condition is true. As long as the condition results true the loop continues, exiting at false.
Syntax:
do
{
block of code to execute;
}
while (condition);

Sample Code:
The following code will increment the value of at least once, execute the code, then increment the value of a again unless the value is less than 10.


$a=0;
do
{$a++
echo "The number is ". $a . "
“;
}
while ($a<10);
?>


Comments are closed.