mIRC Home    About    Download    Register    News    Help

Page 2 of 2 < 1 2
Topic Options
#155379 - 20/08/06 11:31 AM Re: Switch Case??
x64 Offline
Babel fish

Registered: 04/11/03
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.

Top
#155380 - 20/08/06 12:34 PM Re: Switch Case??
Om3n Offline
Fjord artisan

Registered: 06/07/03
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

Top
#155381 - 02/09/06 12:32 AM Re: Switch Case??
IAmParadox Offline
Pikka bird

Registered: 19/09/04
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


Edited by IAmParadox (02/09/06 12:51 AM)

Top
#155382 - 02/09/06 04:03 AM Re: Switch Case??
IAmParadox Offline
Pikka bird

Registered: 19/09/04
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

Top
#155383 - 03/09/06 04:50 AM Re: Switch Case??
IAmParadox Offline
Pikka bird

Registered: 19/09/04
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.

Top
Page 2 of 2 < 1 2