mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
Re: Switch Case?? #155379 20/08/06 10:31 AM
Joined: Nov 2003
Posts: 50
X
x64 Offline
Babel fish
Offline
Babel fish
X
Joined: Nov 2003
Posts: 50
A switch/case would be a great enhancement to speed and efficiency of not only runtime but of coding too. Consider the following script:

if (%command == ban) { ...
} elseif (%command == unban) { ...
} elseif (%command == op) { ...
} elseif (%command == deop) { ...
} elseif (%command == voice) { ...
} elseif (%command == devoice) { ...
}

%command must be evaluated 6 times here in an unbalanced situation (the first commands will execute much sooner than commands at the end of the clause).

In a switch/case:

switch (%command) {
case (unban) ...
case (ban) ...
case (op) ...
case (deop) ...
case (voice) ...
case (devoice) ...
}

Here, %command is evaluated once, the code is 10 times clearer, and if all cases are literal strings, mirc could internally use a hashtable which would mean that all commands would take the same amount of time to execute regardless of where they are on the sequence.

Re: Switch Case?? #155380 20/08/06 11:34 AM
Joined: Jul 2003
Posts: 655
Om3n Offline
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
this would be good indeed,, however it feels a little like 'foreach' dejavu


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
Re: Switch Case?? #155381 01/09/06 11:32 PM
Joined: Sep 2004
Posts: 14
I
IAmParadox Offline
Pikka bird
Offline
Pikka bird
I
Joined: Sep 2004
Posts: 14
run this through your alias and see how it does:
http://www.nomorepasting.com/paste.php?pasteID=67981


EDIT: Fixed a little error

Last edited by IAmParadox; 01/09/06 11:51 PM.
Re: Switch Case?? #155382 02/09/06 03:03 AM
Joined: Sep 2004
Posts: 14
I
IAmParadox Offline
Pikka bird
Offline
Pikka bird
I
Joined: Sep 2004
Posts: 14
I couldn't edit my last post anymore, so here's a version of it without any gotos:

http://www.nomorepasting.com/paste.php?pasteID=67985

Re: Switch Case?? #155383 03/09/06 03:50 AM
Joined: Sep 2004
Posts: 14
I
IAmParadox Offline
Pikka bird
Offline
Pikka bird
I
Joined: Sep 2004
Posts: 14
I guess no one is even reading this thread anymore, but I thought I would add if you put the whole switch case in a while, the break works more like you would expect it to.

Page 2 of 2 1 2