mIRC Home    About    Download    Register    News    Help

Print Thread
#97478 13/09/04 08:07 AM
Joined: Aug 2004
Posts: 18
H
Pikka bird
OP Offline
Pikka bird
H
Joined: Aug 2004
Posts: 18
Hi all,
I don't understand what is the better mode to write code.
I put here anyone example....please tell me what is the better and the faster for writer script.
Thanks a lot.
HS
------------------
on *:op:#:{ if ($chan != #test) if ($opnick == $me) msg # 9»8 Thanks for op 9« }

on *:op:#:{
if ($chan !=#test) if ($opnick == $me) | msg # 9»8 Thanks for op 9« }

on *:op:#:{
if ($chan != #test) {
if ($opnick == $me) {
msg # 9»8 Thanks for op 9«
}
}
}

on *:op:#:{
if ($chan != #test) {
if ($opnick == $me) { msg # 9»8 Thanks for op 9« }
}
}
----------------------------------

#97479 13/09/04 10:59 AM
Joined: Dec 2002
Posts: 788
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 788
There is no "better" way, nor is there an "absolute" one, you code, however YOU find it easiest, however, usually you will find people will 'add' the if statements together.

On *:OP:#:{
if ($chan != #test) && ($opnick == $me) {
msg # 9»8 Thanks for op 9«
}
}

Btw; from your samples above, 3 and 4 are the only ones that will work because, sample 1 has an if in the middle of an if statement, you probably wanted a &&, and similiarly 2 has the same but a | instead of a { as well.

Eamonn.

#97480 13/09/04 11:36 AM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
The first one will work fine, nested if's behave equivalent to using &&.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#97481 13/09/04 12:09 PM
Joined: Dec 2002
Posts: 788
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 788
Oh well, fair enough, although thats not the purpose of an if.

Eamonn.

#97482 13/09/04 05:50 PM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
It works exactly the same as a none nested if statement, it's only like using && because in a nested if, both conditions have to be met, eg:

Code:
if (1) && (2) {  }


Is the same as:

Code:
if (1) {
  if (2) {  }
}


New username: hixxy
#97483 14/09/04 11:05 AM
Joined: Jan 2003
Posts: 20
K
Ameglian cow
Offline
Ameglian cow
K
Joined: Jan 2003
Posts: 20
i would stick with examples 3 & 4 for coding as u will find it much easier to understand if u leave it for a while and come back to it later. coding on a single line can become confusing if u have lots or brackets in it.

#97484 15/09/04 09:55 PM
Joined: Sep 2004
Posts: 12
Pikka bird
Offline
Pikka bird
Joined: Sep 2004
Posts: 12
Nested if's like this are great because you have stuff that can occur when both conditions are met, but you can also have a different thing occur when only the first condition is met.

Handeh wink


Link Copied to Clipboard