The break Keyword in Java


Use break to exit from a loop or switch statement prematurely.

Source Code

for (int i = 0; i < 10; i++) {
    if (i == 5) {
        break; // Exits the loop when i is 5
    }
    System.out.println(i);
}

break is useful for stopping a loop based on a condition inside the loop.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments