mIRC Homepage
Posted By: katz1988 Switch - 17/04/05 05:39 PM
wouldnt it be nice if the switch funtion from c/c++/php is added in the next versions cool
that would save a lot of "IF"s wink
and a lot of nerves
Posted By: SladeKraven Re: Switch - 17/04/05 05:47 PM
Look at the 6th thread below yours. Or if you're lazy click here

You could also use the Search Feature and expand to 5 years. smile
Posted By: tidy_trax Re: Switch - 17/04/05 06:02 PM
For now you can use the /goto workaround.

Code:
; switch ($1) {
goto $1

; case 'a':
:a

dostuff

; break;
return

; case 'b':
:b

dostuff

; break;
return

; case 'c':
:c

dostuff

; break;
return

; default:
:$1

dostuff

; }


The ; comments show you what would be happening if you were using a switch statement.
Posted By: SladeKraven Re: Switch - 17/04/05 06:08 PM
I do like the idea of the switch function and that's a good work around for it. I am all for the function, I'd love to see it implemented in the next version. In my opinion though, I really can't see it being added. But as I said it's just my opinion. smile
Posted By: tidy_trax Re: Switch - 17/04/05 06:19 PM
I'd also like to see a switch statement, for loop and class support (OOP) but it's very unlikely. smile
Posted By: qwerty Re: Switch - 17/04/05 09:40 PM
This trick only works with variables, so you'd have to do
Code:
var %a = $1
goto %a
...
...
[color:green]; default case[/color]
:%a
Posted By: starbucks_mafia Re: Switch - 17/04/05 10:25 PM
Even with what qwerty said, the use of a variable as a default is very kludgey and prone to bugs. Also, using return like that is not the same as using break. break would exit only the switch statement whereas return will exit the scope in which the goto's are called.
Posted By: starbucks_mafia Re: Switch - 17/04/05 10:36 PM
Quote:
Khaled (12/08/2003)

Always nice to have standard programming constructs ie. 'for' and 'case' but if they're going to be slower than existing constructs eg. 'while' and 'goto' which provide more or less the same functionality...

Then again, using /goto is something I avoid myself... I'll move select/case higher up on the to-do list

- Looks like it will be added at some point.
Posted By: SladeKraven Re: Switch - 17/04/05 10:56 PM
Ooh, I must have misread that somewhere. Or if I did read it forgot about it, I can't remember what I had for my dinner yesterday let alone 87 weeks 5 days ago.. crazy
© mIRC Discussion Forums