Continue Statement in java

Continue Statement in java
Continue Statement in java 1

continue statement is used in decision making such as if-else etc .continue statement is completely different from the break statement because continue statement doesn’t exit the loop if the condition is false, continue statement will jump controller again to the starting of the loop.




Continue Statement in java 2

Working of break statement:

Continue Statement in java 3


import java.util.*;
class X2
         public static void main(String args[])
            Scanner s=new Scanner(;
            int i=0,x=0,sum=0;
           for (i=1;i<=5;i++)
 	         System.out.printf("enter %dst number ",i);
 	         if(x<0 || x==0)
             sum += x;
          System.out.printf("the total sum is %d",sum);


enter 1st number 12
enter 2st number 0
enter 3st number -20
enter 4st number 2
enter 5st number 2
the total sum is 16

when program encounters the continue key word ,the program skips the itreartion,in the abov example when the in puts are 0,-20 these are skipped and not inclued in the sum variable.the program output will be 12+2+2=16 and 0,-20 are ignored with the continue statement.

Default image
Vishal Devxo
Vishal is a DevOps engineer and a Backend developer, he spends all his time for creating good tutorials with better visuals and blogging, developed some projects based on Python-Django, some hacking modules and scripts in python
Leave a Reply