KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I came across a case-switch piece of code today and was a bit surprised to see how it worked. The code was: switch (blah) { case a: break; case b: break; case c: case d: case e: { /* code here */ } break; default : return; } To my surprise in the scenario where the variable was c , the path went inside the "code here" segment. I agree there is no break at the end of the c part of the case switch, but I would have imagined it to go through default instead. When you land at a case blah: line, doesn't it check if your current value matches the particular case and only then let you in the specific segment? Otherwise what's the point of having a case?
Tags (comma-separated)
Save Edits
Cancel