Break in Nested Loops : Do While : Language Basics PHP Source Code


PHP Source Code » Language Basics » Do While »

 

Break in Nested Loops




<html>
<head>
<title>Break Nested</title>
</head>
<body>
<?php

     srand((double)microtime() 1000000);
   
     $number = rand(11000);
     $j = 0;
     $outer_loop_itr = 50;
   
     for($i = 1; $i <= $outer_loop_itr; $i++) {
          $j = 0;
          do {
               $j++;
               $number = rand(11000);
               if($number == 999) {
                 break;
               }  
          while(1);
   
          $num_iterations[$i= $j;
     }
     $avg_iterations = (array_sum($num_iterations/ $outer_loop_itr);
     print("an average of " . $avg_iterations);
?>
</body>
</html>
           
       



HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo Language Basics
» Do While