Calculate Primes with continue statement and label in Java

Description

The following code shows how to calculate Primes with continue statement and label.

Example


public class Main {
  public static void main(String[] args) {
    int nValues = 50;
/*ww  w .j  a va  2 s  .  c o m*/
    OuterLoop: for (int i = 2; i <= nValues; i++) {
      for (int j = 2; j < i; j++) {
        if (i % j == 0) {
          continue OuterLoop;
        }
      }
      System.out.println(i);
    }
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Java Language »




Java Data Type, Operator
Java Statement
Java Class
Java Array
Java Exception Handling
Java Annotations
Java Generics
Java Data Structures