switch-case statement without break
If you don't include break in any of case then all the case below will be executed and until it sees break.
And if you don't include break in default then it will cause no effect as there are not any case below this 'Default' case.
And not using break generally considered as a bad practice but some time it may also come handy because of its fall-through nature.For example:
case optionA:
//optionA needs to do its own thing, and also B's thing. //Fall-through to optionB afterwards. //Its behaviour is a superset of B's.
case optionB:
// optionB needs to do its own thing // Its behaviour is a subset of A's. break;
case optionC:
// optionC is quite independent so it does its own thing. break;
You execute everything starting from the selected case up until you see a break
or the switch
statement ends. So it might be that only C is executed, or B and then C, or A and B and C, but never A and C