PHP/Statement/continue

Материал из Web эксперт
Перейти к: навигация, поиск

Continue Statement

 
<html>
 <head>
  <title>Continue Statement</title>
 </head>
 <body>
 <?php
  $i = 0; 
  $passes = "";
  while ( $i < 5 )
  {
    $i++;
    if( $i == 3 ) continue;
    $passes .= "$i ";
  }
  echo("Loop stopped at $i<br>");
  echo("Completed iterations:$passes");
 ?>
 </body>
</html>



continue within a for loop

 
<?php
    $usernames = array("grace","doris","gary","nate","missing","tom");
    for ($x=0; $x < count($usernames); $x++) {
        if ($usernames[$x] == "missing") continue;
        echo "Staff member: $usernames[$x] <br />";
    }
?>



Using continue instead of break

 
<?php
$counter=-3;
for (;$counter<10;$counter++){
    if ($counter==0){
        echo "Skipping to avoid division by zero.<br>";
        continue;
    }
    echo "100/$counter ",100/$counter,"<br />";
}
?>



Using the continue Statement

 
<html>
<head><title>Using the continue Statement</title></head>
<body>
<div>
<?php
    $counter = -4;
    for ( ; $counter <= 10; $counter++ ) {
      if ( $counter == 0 ) {
        continue;
      }
      $temp = 4000/$counter;
      print "4000 divided by $counter is .. $temp<br />";
    }
?>
</div>
</body>
</html>