|
|
PHP while loop statement script and exampleWhile loop in PHP is very simple and similar to while loop in C programming.
In PHP while loop the condition is checked at the beginning of the loop and the
statement inside is executed till the end of the loop, then again the condition
is checked and loop executed. Like this loop is continued till the condition
became false and the loop is then stopped. Here if the condition became
false inside the loop then also the loop continue to execute till the next time
the condition is checked. Here is one simple example of while loop.
<?Php
$j=5; // we assigned a value to the variable here
while($j <10 ){ // loop starts if condition is true
echo " value of \$j= $j <br>";
$j=$j+1;
}
?>
What is the output of this?
value of $j= 5 value of $j= 6 value of $j= 7 value of $j= 8 value of $j= 9
Here we are checking the while condition at the starting of the loop. So the execution of the loop will be done only if condition is satisfied at the beginning. We can read on the difference between do while loop and while loop here. |
|
| |
|
|
|
|
|