Continue statement in Java

 Java continue statement

Unlike break statement, the continue statement doesn't break the loop, whereas, it skips the specific part of the loop and jumps to the next iteration of the loop immediately.

Consider the following example to understand the functioning of the continue statement in Java.

  1. public class ContinueExample {  
  2.   
  3. public static void main(String[] args) {  
  4. // TODO Auto-generated method stub  
  5.   
  6. for(int i = 0; i<= 2; i++) {  
  7.   
  8. for (int j = i; j<=5; j++) {  
  9.   
  10. if(j == 4) {  
  11. continue;  
  12. }  
  13. System.out.println(j);  
  14. }  
  15. }  
  16. }  
  17.   
  18. }  

Output:

0
1
2
3
5
1
2
3
5
2
3
5


Comments

If you have any query or suggestions, Please feel free to write us

Name

Email *

Message *