Can the last case of a switch statement skip including the break? Ans. Even though the last case of a switch statement does not require a break statement at the end, you should add break statements to all cases of the switch statement, including the last case. You should do so primarily because your program has a strong chance of being maintained by someone other than you who might add cases but neglect to notice that the last case has no break statement. This oversight would cause what would formerly be the last case statement to 'fall through' to the new statements added to the bottom of the switch statement. Putting a break after each case statement would prevent this possible mishap and make your program more 'bulletproof.' Besides, most of today's optimizing compilers will optimize out the last break, so there will be no performance degradation if you add it. - Study24x7
Social learning Network
13 Mar 2023 01:10 PM study24x7 study24x7

Can the last case of a switch statement skip including the break? Ans. Even though the last case of a switch statement does not require a break statement at the end, you should add break statements to all cases of the switch statement, including the last case. You should do so p...

See more

study24x7
Write a comment
Related Questions
500+   more Questions to answer
Most Related Articles