Java


Java Tutorial


Admission Enquiry Form

  

Break Statement in Java

What is break statement in Java?

break statement in Java is a Jumping statement, when break is encountered in loop, the loop gets terminated immediately. In can be used in any kind of loop.

Syntax of break statement.

break;




Example of break statement:

//Java program of break statement.
public class BreakStatement {

    public static void main(String[] args) {

int i;

for(i=1;i<=5;i++)
{
if(i==3)
{

break;  //break statement

} //end of if

System.out.println("i is ="+i);

}//end of for loop

}//end of main method

}//end of class BreakStatement


Output:

i is =1
i is =2

In the above example, the for loop will execute 2 times only ,because when condition in if statement is true, break statement will be encountered and the loop will get terminated in the third repetition.