Switch statementshardgeusJuly 4 2005, 12:06:28 UTC
There's a few weird things with switch statements, though...
A lot of times things don't behave quite like you'd expect. One thing is that you can't declare variables in any one of the cases. These days compilers catch it and won't let you do it, but I can remember running into weird behavior a few years ago.
Also, you have to manually break after every one of your cases. I can't tell you how many times I have had subtle bugs in my code that ultimately are the fault of one missing break statement causing two different cases to execute. That's a tricky one to find.
Comments 4
Reply
Sophie = jump if arg!
Reply
Reply
A lot of times things don't behave quite like you'd expect. One thing is that you can't declare variables in any one of the cases. These days compilers catch it and won't let you do it, but I can remember running into weird behavior a few years ago.
Also, you have to manually break after every one of your cases. I can't tell you how many times I have had subtle bugs in my code that ultimately are the fault of one missing break statement causing two different cases to execute. That's a tricky one to find.
Reply
Leave a comment