Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
165 views
in JAVA by (159k points)
What is the "break" statement in Java?

Please log in or register to answer this question.

1 Answer

0 votes
by (159k points)

In Java, the "break" statement is a control statement that is used to terminate the execution of a loop, a switch statement or a labeled block.

When used inside a loop (such as a for loop, while loop or do-while loop), the "break" statement causes the loop to immediately terminate and the program control is transferred to the statement immediately following the loop.

For example, consider the following code snippet:

for (int i = 1; i <= 10; i++) {
    if (i == 5) {
        break;
    }
    System.out.println(i);
}
 

In this code, the loop will iterate from 1 to 10, but when the value of i becomes 5, the "break" statement will be executed and the loop will be terminated. So, the output of this code will be:

1
2
3
4
 

When used inside a switch statement, the "break" statement causes the program control to exit the switch statement. If the "break" statement is not used, the program will continue executing the statements in the following cases until it reaches a "break" statement or the end of the switch block.

Overall, the "break" statement is a useful tool for controlling the flow of a program in Java.

Related questions

0 votes
2 answers
asked Apr 19, 2023 in JAVA by kvdevika (159k points)
0 votes
1 answer
0 votes
1 answer
asked Apr 28, 2023 in JAVA by kvdevika (159k points)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...