|
|
Tutorials » Php »
|
Topic |
What is Do While Structure?
|
|
Explanation |
|
Do While statement is same as the while statement, the only difference is that it evaluates
the expression at the end.
Syntax
do
{
Statements
}while (expr1);
In do while, the statements are executed first, then the expr1 is checked, only drawback of
Do While is that it may execute statements once even if the condition is false.
Example
<?php
$c =1;
do {
echo $c;
}
while ($c>5);
?>
In the above example the value of $c should be displayed only if its greater than 5,but using the
Do while statement it displays the value of $c as 1 first and then checks the expression or condition.
Example
<?php
$c = 6;
do
{
if ($c>5)
{
echo "Enter the a value less than 5";
break;
}
}
while ($c<5);
?>
Use the "Break" statement to terminate the code execution in a loop
|
|
A Note |
Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial.
Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.
|
|
|
|