Java - continue with Label


An unlabeled continue statement continues the current for loop, while loop, and do-while loop.

A labeled continue statement can continue in the outer loop.


The following code shows how to print lower half of the 3x3 matrix using a continue statement.


public class Main {
  public static void main(String[] args) {
    outer: // The label "outer" starts here
    for (int i = 1; i <= 3; i++) {
      for (int j = 1; j <= 3; j++) {
        System.out.print(i + "" + j);
        if (i == j) {
          System.out.println(); // Print a new line
          continue outer; // Continue the outer loop
        }/*from   ww  w. j a va2 s .c o m*/



Related Topic