title: Breaking out of complex loop structure in Java
body: <p>Im a beginner in Java. I have the following loop structure: </p>
  
  <pre><code>loop1:
  for(int j=0; j&lt;a.size(); j++){
  
      if(a.get(j).equals(10)){
          System.out.println(a.get(j));
      } else {
          do {
              System.out.println(a.get(j));
          } while(a.get(j).equals(20)); 
          break loop1;
      }
  }
  </code></pre>
  
  <p>This is a basic structure of what im trying to do. So I want to break out of the <code>for</code> loop when the <code>do while</code> loop in the <code>else</code> part is satisfied(the do- while loop executes once irrespective of condition mentioned, I dont want to exit the loop then, but I want to exit the loop when the condition is actually satisfied). How do I do that? I tried breaking as shown in code, but it stops after first iteration through <code>do-while</code> loop. Where am I going wrong? </p>
  
  <p>I want to print the values in the <code>ArrayList a</code> starting from 10 until 20...and 10 can be anywhere in the list and not the beginning.</p>
  
  <pre><code>Eg. ArrayList a contains {1,2,3,4,5,6,7,8,9,10,11,12,13...20}
  I want to print values in the ArrayList from values 10 to 20 (including 10 and 20). 
  </code></pre>
  
  <p>There are no duplicate elements in the list. So there is only one 10 and one 20 in the list and it is always in the increasing order. </p>