PHP while loop
PHP while is an iterative loop by which we can repeat a condition based on condition. The general form of PHP while loop is
PHP while loop starts with the name while and then condition. If the condition is true then it allows to execute the statement otherwise it terminates the while loop. So we can say that the condition part returns true or false.
while(condition)
{
executed satement
}
PHP while loop starts with the name while and then condition. If the condition is true then it allows to execute the statement otherwise it terminates the while loop. So we can say that the condition part returns true or false.
PHP while loop example
Now we try to do a problem using php while loop. The problem is to add 1,2,3,4,5,6,7,8,9 and 10. So the code is<?phpIf the while condition is not true then the PHP while loop will not execute the inner code. Here is an example.
$value=1;
$sum=0;
while($value<=10)
{
$sum=$sum+$value;
$value++;
}
echo $sum;
?>
<?php
$value=1;
$sum=0;
while(!$value==1)
{
$sum=$sum+$value;
$value++;
}
echo $sum;
?>
Comments
Post a Comment