That's a nice use of brackets there. I must admit I'd never even thought of that to make goto more readable.

Although that code does emulate the majority of functions a scripter would use a switch statement for there are a few things where it falls short...
  • There is no way to break from the switch without leaving the entire scope (unless you use an additional variable check per case of course).
  • If you have multiple switches in the same peice of code they mustn't have duplicate case values
  • Limited values for the case value (ie. only literals or variables, no identifiers, no spaces)
  • You can't have a case with the value "error" alongside error handling code (OK now I'm just picking holes).


Only the first one of those is really a problem, but it is a pretty significant one. Trying to emulate break effectively renders the code unreadable and you lose that nice warm feeling that your code is efficient.

The goto method is an elegant hack, but it is a hack nonetheless. I'm sure no-one is ever going to die from the lack of a switch statement in mIRC but it sure wouldn't suck if it ever popped up.

In addition to the switch/case/default suggestion here I'll tag on a suggestion for an "else" clause in place of "default" which only triggers if no other cases have triggered (basically a "default" which can't be cascaded into).


Spelling mistakes, grammatical errors, and stupid comments are intentional.