Java Break Statement

In this tutorial you will learn about the Java Break Statement and its application with practical example.

Java Break Statement

Java break statement inside any loop gives you a way to break or terminate the execution of the loop containing it and transfers the execution to the next statement following the loop. It is almost always used with if..else construct.

Java Break Statement Flow Diagram

cpp_break_statement_example

Syntax:-

Example:-

In the above program, the variable count is initialized as 0. Then a while loop is executed as long as the variable count is less than 10. Inside the while loop, the count variable is incremented by 1 with each iteration (count = count + 1). Next, we have an if statement that checks the variable count is equal to 5, if it returns TRUE causes the loop to break or terminate. Within the loop, there is a court statement that will execute with each iteration of the while loop until the loop breaks. Then, there is a final cout statement outside of the while loop.

When we run this code, our output will be as follows –

Output:-

java_break_statement_example

In this tutorial we have learn about the Java Break Statement and its application with practical example. I hope you will like this tutorial.