Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

Break in Nested Loops

Mon Oct 27, 2008 12:45 pm

Code:
<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>




Post a reply
  Related Posts  to : Break in Nested Loops
 java Break Line for text     -  
 Nested function     -  
 Layout with Nested JPanels     -  
 nested ordered list     -  
 Nested classes(inner class) in java     -  
 C++ for loops     -  
 C++ For Loops     -  
 Nesting Two for Loops     -  
 Loops and Branching     -  
 Re: Lets Learn C++----->(Lesson 4) Loops     -  

Topic Tags

PHP Loops