break within a for loop : break statement « Statement « PHP






break within a for loop

 
<?php
   $primes = array(2,3,5,7,11,13);
   for($count = 1; $count++; $count < 1000) {
      $randomNumber = rand(1,50);
      if (in_array($randomNumber,$primes)) {
         break;
      } else {
         echo "<p>Non-prime number encountered: $randomNumber</p>";
      }
   }
?>
  
  








Related examples in the same category

1.Break statement
2.Breaking a Loop
3.Using the break Statement
4.Break 1 or break 2
5.Break Statement
6.Using the break Statement
7.The break command applies to both loops and switch/case statements
8.Using break to avoid division by zero