Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a <a href="http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html" rel="nofollow">labelled loop</a>, when <code>break group_skip;</code> statement is executed, it will jump out of the do while loop which is labelled as <code>group_skip</code></p> <pre><code>boolean isTrue = true; outer: for (int i = 0; i &lt; 5; i++) { while (isTrue) { System.out.println("Hello"); break outer; } // end of inner while System.out.println("Outer loop"); // does not print } // end of outer loop System.out.println("Good Bye"); </code></pre> <p>This outputs </p> <pre><code>Hello Good Bye </code></pre> <p>You can get the concept clear here.</p> <ul> <li>There is a labelled <code>for</code> loop called <code>outer</code> and there is inner <code>while</code> loop</li> <li>When inner for loop is being executed, it encounters <code>break outer;</code> statement</li> <li>The <code>outer for loop</code> has a <code>System.out.println"Outer loop"</code> statement but that does not get printed.</li> <li>This is because <code>break outer</code> causes the control to jump out of labelled <code>for</code> loop directly</li> </ul> <p>Now this example for <code>continue</code> statement</p> <pre><code>outer: for (int i = 0; i &lt; 5; i++) { for (int j = 0; j &lt; 5; j++) { System.out.println("Hello"); continue outer; } // end of inner loop System.out.println("outer"); // this won't print } // end of outer loop System.out.println("Good bye"); </code></pre> <p>This prints </p> <pre><code>Hello Hello Hello Hello Hello Good bye </code></pre> <ul> <li>There is a labelled <code>for</code> loop here and an inner <code>for</code> loop</li> <li>Inner <code>for</code> loop prints <code>Hello</code> and continues to the <code>outer</code> loop.</li> <li>Because of this, the statements below inner <code>for</code> loop are skipped and <code>outer</code> loop continues to execute.</li> <li>At the end of <code>outer</code> for loop, <code>Good Bye</code> is printed</li> </ul> <p>Hope this makes everything clear.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload