Java Language / Java Break and Continue Statements

Java Break
It is used to jump out of a loop.

Sample Program to print numbers Output
public class numbersprint
{
public static void main(String[] args)
{
for (int i = 0; i < 5; i++)
{
if (i == 4)
{
break;
}
System.out.println(i);
}
}
}
0
1
2
3

Java continue
It is used to skip the loop for once.

Sample Program to print numbers Output
public class numbersprint
{
public static void main(String[] args)
{
for (int i = 0; i < 5; i++)
{
if (i == 2)
{
continue;
}
System.out.println(i);
}
}
}
0
1
3
4


Home     Back