The purpose of break is to stop any subsequent cases from executing, but there are no other statements after case 3, so that break-statement is completely unnecessary.
Yes it is. But it's also a good habit to get into. Months later, you might be changing your program and add some more cases - say case 4 and case 5. But unless you remember to go add the break into case 3, your case 3 will fallthrough to case 4 (but none of the others will), creating a very confusing glitch.
It's good programming practice to always finish each case with a break, unless you really do want it to fallthrough. And that's exactly what we will in the next example.
|
|