mIRC Homepage
Posted By: homeless What is better code? - 13/09/04 08:07 AM
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« }
}
}
----------------------------------
Posted By: Coolkill Re: What is better code? - 13/09/04 10:59 AM
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.
Posted By: starbucks_mafia Re: What is better code? - 13/09/04 11:36 AM
The first one will work fine, nested if's behave equivalent to using &&.
Posted By: Coolkill Re: What is better code? - 13/09/04 12:09 PM
Oh well, fair enough, although thats not the purpose of an if.

Eamonn.
Posted By: tidy_trax Re: What is better code? - 13/09/04 05:50 PM
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) {  }
}
Posted By: Krayzee Re: What is better code? - 14/09/04 11:05 AM
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.
Posted By: GSEqUaTe Re: What is better code? - 15/09/04 09:55 PM
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
© mIRC Discussion Forums