Tuesday, December 13, 2011

Using Continue statement in java with example

Usage of Continue:
continue statement is used to skip the execution of the  loop based on some condition.The following loop uses the continue statement.It will print values from 0 to 9 except 5.When i value equals to 5,the loop is skipped.
class continue1
{
public static void main(String args[])
{
for(int i=0;i<10;i++)
{
if(i==5)
continue;
System.out.println(i);
}
}
}


Output:
0
1
2
3
4
6
7
8
9