Loops are used to execute the specified block of codes for a number of times, or while the specified condition is true.
In PHP we have the following looping statements. They are
- While loop
- Do-While loop
- For loop
- foreach loop
WHILE loop:
The while loop is used to execute the block of code while the specified condition is true. While loop is a entry controlled loop;
Syntax:
While (condition)
{
---//block of codes to be executed if the condition is true.
---
}
Example:
$i=1;
while($i<=5)
{
echo "The number is " . $i . "
";
";
$i++;
}
Output:
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
0 comments:
Post a Comment