Usage of Break:
break statement is used to terminate the loop based on some condition.The following loop uses the break statement.It will print values from 0 to 4.When i value equals to 5,the loop is terminated.
class break1
{
public static void main(String args[])
{
for(int i=0;i<10;i++)
{
if(i==5)
break;
System.out.println(i);
}
}
}
Output:
0
1
2
3
4