Home  >  Article  >  Java  >  An example to help you understand the difference between break and continue

An example to help you understand the difference between break and continue

怪我咯
怪我咯Original
2017-06-26 11:35:491940browse

public class Test {
  public static void main(String[] args) {
    for (int i = 0; i < 5; i++) {
      if (i == 2)
        // break;
        continue;
      System.out.println(i);
    }
  }
}

Conclusion: break is used to terminate the entire loop, while continue is used to terminate a certain loop.

The above is the detailed content of An example to help you understand the difference between break and continue. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn