The Labeled continue statement : Continue Statement « Statement Control « Java Tutorial






public class MainClass {
  public static void main(String[] args) {
    int limit = 20;
    int factorial = 1;

    OuterLoop: for (int i = 1; i <= limit; i++) {
      factorial = 1;
      for (int j = 2; j <= i; j++) {
        if (i > 10 && i % 2 == 1) {
          continue OuterLoop;
        }
        factorial *= j;
      }
      System.out.println(i + "! is " + factorial);
    }
  }
}
1! is 1
2! is 2
3! is 6
4! is 24
5! is 120
6! is 720
7! is 5040
8! is 40320
9! is 362880
10! is 3628800
12! is 479001600
14! is 1278945280
16! is 2004189184
18! is -898433024
20! is -2102132736








4.9.Continue Statement
4.9.1.The continue Statement
4.9.2.The continue statement: skips all or part of a loop iteration
4.9.3.The Labeled continue statement
4.9.4.Calculating Primes: using continue statement and label