mIRC Home    About    Download    Register    News    Help

Print Thread
#117594 17/04/05 05:39 PM
Joined: Nov 2004
Posts: 9
K
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
K
Joined: Nov 2004
Posts: 9
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

#117595 17/04/05 05:47 PM
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
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

#117596 17/04/05 06:02 PM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
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.


New username: hixxy
#117597 17/04/05 06:08 PM
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
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. smile

#117598 17/04/05 06:19 PM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
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. smile


New username: hixxy
#117599 17/04/05 09:40 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
This trick only works with variables, so you'd have to do
Code:
var %a = $1
goto %a
...
...
[color:green]; default case[/color]
:%a


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#117600 17/04/05 10:25 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
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.
#117601 17/04/05 10:36 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#117602 17/04/05 10:56 PM
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
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.. crazy


Link Copied to Clipboard