Loop Statement

For
for (initialization; condition; increment){
   code to be executed;
}
While
while (condition) {
   code to be executed;
}
Do..While
do {
   code to be executed;
}
while (condition);
Foreach
foreach (array as value) {
   code to be executed;
}
Break
<html>
   <body>

      <?php
         $i = 0;

         while( $i < 10) {
            $i++;
            if( $i == 3 )break;
         }
         echo ("Loop stopped at i = $i" );
      ?>

   </body>
</html>

output

Loop stopped at i = 3
Continue
<html>
   <body>

      <?php
         $array = array( 1, 2, 3, 4, 5);

         foreach( $array as $value ) {
            if( $value == 3 )continue;
            echo "Value is $value <br />";
         }
      ?>

   </body>
</html>

output

Value is 1
Value is 2
Value is 4
Value is 5

results matching ""

    No results matching ""