Home >Java >javaTutorial >How to use continue in java

How to use continue in java

王林
王林Original
2020-05-11 11:31:079471browse

How to use continue in java

Usage examples of continue in JAVA:

public class test{
 public static void main(String [] args){
  for(int i=0;i<=10;i++){
   if(i%2!=0){
    continue;   
   }
   System.out.println(i);  
  }
 }
}

continue means to interrupt this cycle and start the next one.

Combined with this code is. When i is an odd number, no printing is done, the loop ends directly and the next time starts.

(Video tutorial recommendation: java video)

Instance 2:

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

Output result:

1 3 4 5

Recommended tutorial:java introductory program

The above is the detailed content of How to use continue in java. 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