continue ;andcontinue Lablename ;
1) used to break regular flow of control.
2) used to perform a early part of iteration.
If the continue is used in the innermost for loop then control will reach first at the increment / decrement part of for loop and then condition part of for loop.
For example:
for(int i=0; i<=5 ; i++)
{
if(i%2 == 0)
{
continue;
}
else
{
System.out.println("i=" + i);
}
}
Output: i=1
i=3
i=5
In this code when compiler reach at the continue statement then it breaks the regular flow and transfer the control to the i++ statement in the for loop and after incrementing the value of i it get transfered to the i<=5 statement.
Now we will discuss the role of continue with lablename.
For example:
lbl : for(int i=0; i<2 ; i++)
{
for(int j=0; j<3 ; j++)
{
if(i==j)
continue lbl;
System.out.println("j=" + j);
}
System.out.println("i=" + i);
}
Output: j=0
If we want to move the control to the outer loop then we use the lablename . lablename is user-defined . In this case we have used the lable lbl right befor the outer for loop.