Programming Loops 



{
   echo " counter = " . $counter . "<BR>";
   $counter ;
}



?> 




5. Do ... While loops



This type is loop is almost identical to the while loop,except that the condition comes at the end.


 


do
statement
while (condition)


 


The difference is that your statement gets executed at least once. In a normal while loop,the condition could be met before your statement gets executed.


6. The break statement 



Break statement is used to stop the loop while loop is running to complete its round.


 


<?



$counter = 1;
while ($counter < 11)


{
   echo " counter = " . $counter . "<BR>";
   if($counter==7) break;


   $counter ;
}



?> 

1. For Loops


The loop goes round and round. Loops are used to redo the same action again and again until the limit you set.



 


for (start value; end value; update expression)


{}



 


 


<?
$counter = 0;
for($start=1; $start < 11; $start )


{
     $counter = $counter 1;
     echo $counter . "<BR>";
}


// $start equivalent to the $start = $start 1;



// $start-- equivalent to the $start = $start - 1;



?>



4. While Loops


The structure of a while loop is more simple than a for loop,because you’re only evaluating the one condition. The loop goes round and round while the condition is true. When the condition is false,the programme breaks out of the while loop.


 


while (condition)


{
    statement
}


 


<?



$counter = 1;
while ($counter < 11)


                    

Copyright © 2008 VisualBuilder. All rights reserved