Understanding break in Java


break is used to exit from a loop or switch statement.

Source Code

public class BreakExample {
    public static void main(String[] args) {
        for (int i = 1; i <= 10; i++) {
            if (i == 6) {
                break;
            }
            System.out.println("i: " + i);
        }
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments