java - Why do we need break after case statements? -
why doesn't compiler automatically put break statements after each code block in switch? historical reasons? when want multiple code blocks execute?
sometimes helpful have multiple cases associated same code block, such as
case 'a': case 'b': case 'c': dosomething(); break; case 'd': case 'e': dosomethingelse(); break;
etc. example.
in experience, bad style "fall through" , have multiple blocks of code execute 1 case, there may uses in situations.
Comments
Post a Comment