View Single Post
  #11 (permalink)  
Old 04-18-2008, 03:28 AM
senraj senraj is offline
D-Web Master
 
Join Date: Jul 2007
Posts: 418
senraj is on a distinguished road
Post Re: Operations in PHP

Hi,

or . . . do: This is basically shorthand for a while loop where the condition is whether a particular variable has yet to reach a certain value. Each time the loop is executed the variable is generally incremented or decremented. This kind of control statement is useful when you want to count through a series of numbers or objects, or repeat a set of statements of particular number of times. For example,


PHP Code:
$sum 0;
for ( 
$a 1$a <= 10$a++ ) 
{
  
$sum += $a;
}

echo 
"Sum of numbers from 0 to 10 equals $sum.";

// The for loop is just shorthand for the following while loop:

$a 1;
while ( 
$a <= 10 
{
  
$sum += $a;
  
$a++;

__________________
Regards,
Senraj.A
Reply With Quote