mIRC Home    About    Download    Register    News    Help

Print Thread
#23202 08/05/03 05:36 PM
Joined: May 2003
Posts: 1
C
Mostly harmless
OP Offline
Mostly harmless
C
Joined: May 2003
Posts: 1
Would it be possible to have select case built in so it's more readable than several if-then-elseif- codes?


Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Been suggested numerous times, but I'll say it again, I'd love to see a switch statement implemented in mIRC.

Joined: Feb 2003
Posts: 32
S
Ameglian cow
Offline
Ameglian cow
S
Joined: Feb 2003
Posts: 32
So would I, There are alternatives to multiple if-then-else, but case statements is one of the things like FOR loops and arrays that I would love to see added just for the sake of elegance.

Joined: Jan 2003
Posts: 52
L
Babel fish
Offline
Babel fish
L
Joined: Jan 2003
Posts: 52
No real need:

test {
if ($istok(1.2.3,$1,46)) { goto $1 }
else { goto default }
:1
echo -a 1
goto endcase
:2
echo -a 2
goto endcase
:3
echo -a 3
goto endcase
:default
echo -a DEFAULT
:endcase
}

/test 1
/test 2
/test 3
/test ANYTHING ELSE.

Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Thats an ugly ugly hack. And honestly, I really wish people wouldn't even post things like this. It's obvious switch isn't needed, as the original poster said, if/else works just fine. We aren't saying "is there a way this can be done?" we are saying "here is a better way to do this, please implement it".

Using $istok like you have there won't work in all situations. Example:

test {
if ($istok(1.2.2.3.3.4,$1,46)) { goto $1 }
else { goto default }
:1.2
echo -a 1.2
goto endcase
:2.3
echo -a 2.3
goto endcase
:3.4
echo -a 3.4
goto endcase
:default
echo -a DEFAULT
:endcase
}
/test 1.2
DEFAULT
/test 2.3
DEFAULT
/test 3.4
DEFAULT

If that were in a switch() it wouldn't have gone to the default, it would have gone to the case for 1.2, 2.3, and 3.4

Joined: Jan 2003
Posts: 52
L
Babel fish
Offline
Babel fish
L
Joined: Jan 2003
Posts: 52
1. You could change the token C. Stupid point.
2. I was giving the guy an idea/suggestion, BLOW OFF.

Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Or even faster.
Code:
alias test {
  var %a = $1
  goto %a
  :1
  echo -a 1 
  return
  :2
  echo -a 2
  return
  :%a
  echo Default
}
 
/test 1 ... 1
/test 2 ... 2
/test 3 ... Default

Labels, however, cannot contain spaces. If you have a label named "1", and another label named "1 2", doing a /goto 1 2 will jump to the first one.


Link Copied to Clipboard