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

How to use continue in java

王林
Release: 2020-05-11 11:31:07
Original
9467 people have browsed it

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);  
  }
 }
}
Copy after login

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);
}
}
}
Copy after login

Output result:

1 3 4 5
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template