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

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -