The break Statement in switch Cases in Java


Within a switch statement, the break keyword stops the execution of more code and case testing.

Source Code

int day = 2;
switch (day) {
    case 1:
        System.out.println("Monday");
        break;
    case 2:
        System.out.println("Tuesday");
        break;
    // Additional cases
}

Always use break in each case of your switch statements unless you intentionally want to “fall through” to the next case.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments