PHP while loop is used to execute statement/s if the condition is true until a certain condition is false.
Syntax for the while loop
while (condition/s)
{
//statement to be executed
}
Let's say we will display numbers from one (1) to ten (10).
Output
PHP Code
<?php
$i=1;
while($i<=10)
{
echo $i;
$i++;
}
?>
The $i=0 serves as the starting point of our while loop. If the condition holds true, which the value of i is 10 or lesser, then the body of the loop which is to display the value of i and increment will be executed. After the execution, the condition will be tested again and again until the condition becomes false.
0 comments:
Post a Comment