title: Nested loop not iterating properly
body: <p>I have this piece of Code in which there are two loops 'i' and 'j'.</p>
  
  <p>'j' is the inner loop variable and it supposed to run 999 to 100 on single run of outer loop.</p>
  
  <p>but it runs randomly like,
  suppose i=999</p>
  
  <p>j=912</p>
  
  <p>j=911</p>
  
  <p>j=910</p>
  
  <p>j=909</p>
  
  <p>j-908</p>
  
  <p>j=907</p>
  
  <p>j=906</p>
  
  <p>then suddenly inner loop quits, decreament 1 from outer loop and makes i=998</p>
  
  <p>then start 'j' loop</p>
  
  <p>j=908</p>
  
  <p>j=907</p>
  
  <p>j=906</p>
  
  <p>j=905</p>
  
  <p>j=906</p>
  
  <p>j=905</p>
  
  <p>j=904</p>
  
  <p>j=903</p>
  
  <p>j=902</p>
  
  <p>then quits innerloop ................</p>
  
  <pre><code>    int product=0;
      mainloop:
      for(int i=999;i&gt;99;i--){
          for(int j=999;j&gt;99;j--){
              boolean flag= doSomething(i*j);
              if(flag){
                  product=i*j;
                  System.out.println("Digits are: "+i+" and "+j);
                  break mainloop;
              }
          }
      }
  
   public  boolean doSomething(int product){
          String original= Integer.toString(product),reverse="";
          int length = original.length();
          for ( int i = length - 1; i &gt;= 0; i-- )
              reverse = reverse + original.charAt(i);
          return (original.equals(reverse));
  
  
      }
  </code></pre>
  
  <p>why is it happening? why inner loop doesnot complete cycle from 999 to 100? </p>
  
  <p><strong>EDIT:</strong> To clear, 'flag' will be true only if j=913 and i=993 , this is the main issue that loop doesn't break at this point because 'j' never comes to 913 but it randomly generates number.Moreover 'break' will break the mainloop not only the inner loop.</p>