Break in Nested Loops : do while « Statement « PHP






Break in Nested Loops


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

     srand((double)microtime() * 1000000);
   
     $number = rand(1, 1000);
     $j = 0;
     $outer_loop_itr = 50;
   
     for($i = 1; $i <= $outer_loop_itr; $i++) {
          $j = 0;
          do {
               $j++;
               $number = rand(1, 1000);
               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>
           
       








Related examples in the same category

1.Counting to 10 with do ... while
2.Do-While Loop
3.do while loop with counter
4.do while with integer counter
5.do...while loop is executed at least once
6.Do while loop
7.The do...while Statement