|
|
Joined: Nov 2004
Posts: 9
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Nov 2004
Posts: 9 |
wouldnt it be nice if the switch funtion from c/c++/php is added in the next versions that would save a lot of "IF"s and a lot of nerves
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
Look at the 6th thread below yours. Or if you're lazy click hereYou could also use the Search Feature and expand to 5 years.
|
|
|
|
Joined: Nov 2003
Posts: 2,327
Hoopy frood
|
Hoopy frood
Joined: Nov 2003
Posts: 2,327 |
For now you can use the /goto workaround. ; 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.
New username: hixxy
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
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.
|
|
|
|
Joined: Nov 2003
Posts: 2,327
Hoopy frood
|
Hoopy frood
Joined: Nov 2003
Posts: 2,327 |
I'd also like to see a switch statement, for loop and class support (OOP) but it's very unlikely.
New username: hixxy
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
This trick only works with variables, so you'd have to do var %a = $1
goto %a
...
...
[color:green]; default case[/color]
:%a
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
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.
Spelling mistakes, grammatical errors, and stupid comments are intentional.
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
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.
Spelling mistakes, grammatical errors, and stupid comments are intentional.
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
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..
|
|
|
|
|
|