Like the break statement, the continue statement also skips the remaining statements of the body of the loop where it is defined but instead of terminating the loop, the control is transferred to the beginning of the loop for next iteration. The loop continues until the test condition of the loop becomes false.
When used in the while and do-while loops, the continue statement causes the test condition to be evaluated immediately after it. But in case of for loop, the increment/decrement expression evaluates immediately after the continue statement and then the test condition is evaluated.
It is simply written as
continue;
Here is the Java Example for the program JavaContinueStatementExample :
public class JavaContinueStatementExample
{
public static void main(String[] args)
{
try
{
int[] arrayOfInts = { 92, 37, 31, 59, 112, 176 , 230, 81, 62, 7 };
int search = 112;
System.out.print("All Elements are : ");
for(int i=0; i < arrayOfInts.length ; i ++)
{
if(arrayOfInts[i] == search)
continue;
else
System.out.print(arrayOfInts[i] + " , " );
}
}
catch (Exception e){}
}
}