Thursday, December 17, 2009

9:21 AM
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

  1. While loop
  2. Do-While loop
  3. For loop
  4. 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: