break Statement

break Statement

The break statement can be used in these ways:

  • break is used inside the loop to come out of it.
  • break is used inside the switch block┬áto come out of it.
Example
public class test
{
public static void main(String args[])
{
for(int i=1; i<10; i++)
{ if(i == 5)
break;
System.out.println(“value is : ” + i);
}
}
}

Output:
value is : 1
value is : 2
value is : 3
value is : 4

Leave a Reply

Your email address will not be published. Required fields are marked *