mIRC Homepage
Posted By: The_JD /endif - 14/02/08 03:18 AM
Well the title is quiet obvious.
/endif (I think its self explanatory).

at the moment, I find myself having to do this too often:

Code:
if (1) {
  if (Blah) { dothis }
  else { dothat }
}
if (1) {
  if (blah2) { dothis......
Posted By: RoCk Re: /endif - 14/02/08 03:23 AM

You may think it's self explanatory but it's not.
Posted By: Bekar Re: /endif - 14/02/08 06:03 AM
The hell do you want 'endif'?

You structure an If correctly, and it's totally unnecessary!
Posted By: genius_at_work Re: /endif - 14/02/08 07:10 AM
Brackets negate the need for endif/fi/esac etc statements. All commands associated with a single if statement are contained within the brackets.

-genius_at_work
Posted By: The_JD Re: /endif - 14/02/08 02:19 PM
Lets say I need to parse two variables. %one and %two

If (%one == 1) echo one ;Works Fine
elseif (%one == 2) echo two ;Works Fine
else echo three or above ;Works Fine

if (%two == a) echo a ;Works Fine
elseif (%two == b) echo b ;Dosnt work
else echo c-z ;Dosnt work

the only current work-around is to use nested ifs

So do you both see a problem with adding this or just bothering to reply because you dont need it?

Edit: Obviousouly, using /endig wouldnt be required, but optional.
Posted By: Riamus2 Re: /endif - 14/02/08 02:28 PM
I'm still not seeing anything that shows a need for endif in either example you gave. Can you give an example showing how you want to use endif and how it would look without it for comparison?

endif just tells the program/script that it's the end of the IF statement. The } (or the end of the line if no {}'s are used) also does this. I just don't see where you're going with this.
Posted By: The_JD Re: /endif - 14/02/08 02:33 PM
basically, this will not work

Code:
if (1) echo hi
else echo byte

if (2) echo hello
else echo see ya!


This will:
Code:
if (1) echo hi
else echo byte
endif
if (2) echo hello
else echo see ya!


It will reset the if's so that the future elseif and else will be able to 'catch' it again

Think about it like resetting 'else'
Posted By: Riamus2 Re: /endif - 14/02/08 02:42 PM
Your first example would work fine. Any IF following an ELSE will act as if the previous IF/ELSEIF/ELSE wasn't there.
Posted By: The_JD Re: /endif - 14/02/08 02:44 PM
the if resets the else's?
*tests*
Posted By: The_JD Re: /endif - 14/02/08 02:47 PM
wow, It does work

*CANCEL THAT REQUEST!!!*

Thanks Riamus.

Code i used:
Code:
alias testif {
  if (a) echo -a 1
  else echo -a 2
  if (b = c) echo -a 3
  else echo -a 4
}


I expected it to echo "1" but it did both "1" and "4".
Not sure if its the IF or the ELSE that resets it, but it works.
Posted By: Riamus2 Re: /endif - 14/02/08 02:47 PM
Well... reverse that -- The ELSE "resets" the IFs. smile


EDIT:
As a note, ELSEIF also "resets" the IF. Only another ELSEIF or ELSE will be part of the previous IF. If you used another IF, it would act as a new one.
Posted By: RoCk Re: /endif *DELETED* - 14/02/08 02:47 PM

But the first one does work. Did you test any of this or just assuming?

~ Edit ~
I tried to delete but was too late.

Posted By: The_JD Re: /endif - 14/02/08 02:49 PM
I just assumed, due to common logic. I would not expect it to be reset without endif
Posted By: genius_at_work Re: /endif - 14/02/08 02:52 PM
That'll teach you for learning VB. :P

-genius_at_work
Posted By: The_JD Re: /endif - 14/02/08 02:57 PM
You have a point there :P

You would generally expect the if not to be reset with an endif though (or nested, as its a new level).

Now im curious about if PHP resets the if's in the same way. I have made many nested ifs in PHP because of this LOL
Posted By: The_JD Re: /endif - 14/02/08 02:59 PM
I've noticed a few mIRC scripters use "else if" rather than "elseif".

So would this reset the if (as you would expect) or act as an elseif?

Edit: Now that I think about it clearly, I guess the "else if" would produce a new "if" nested from the else?
Posted By: Riamus2 Re: /endif - 14/02/08 03:03 PM
Technically speaking, an ELSEIF is really just an ELSE followed by a "nested" IF.

Code:
IF () {}
ELSE {
  IF () {}
  ELSE {
    IF () {}
  }
}


As such, ELSEIF and ELSE IF do the same thing. Personally, I think that using ELSEIF instead allows you to clearly see that you're using the same original IF as a basis for your ELSE's. But as far as the script goes, you can use it as ELSEIF, ELSE IF, or nested as shown above, and it will do the same thing in the end.
Posted By: The_JD Re: /endif - 14/02/08 03:06 PM
Oh noes! Another long post brought to you by riamus (well, it could have been longer) :P


Haha yeh, Im starting to understands mIRC's "if"s a little better now.
Kinda funny, Considering how many people come to me for help and I didnt know something this simple laugh
Posted By: genius_at_work Re: /endif - 14/02/08 03:18 PM
IFs in PHP work similar to mIRC, almost identically, in fact.

PHP uses { } brackets for multi-line "THEN" statements. Any additional IFs that are within the { } of a previous IF/ELSEIF/ELSE are nested. Any IFs that are outside the { } of previous IF/ELSEIS/ELSE are not considered part of those previous structures. Each new IF statement that is not nested, resets the IF structure (as opposed to being reset by the ELSEIF and ELSE, because those two statements are optional).

-genius_at_work
Posted By: The_JD Re: /endif - 14/02/08 03:20 PM
Thanks!!! I think this topic is answered now lol (and I feel like a took tool).
Posted By: qwerty Re: /endif - 14/02/08 04:44 PM
Quote:
Technically speaking, an ELSEIF is really just an ELSE followed by a "nested" IF.
Technically speaking that's not quite correct :P

ELSEIF and ELSE IF are indeed equivalent in mirc, but they are not equivalent to ELSE { IF() {} }. The difference is that you can have two or more ELSEIFs or ELSE IFs but never more than one ELSEs, for example:

//if (0) echo a | elseif (0) echo b | elseif (1) echo works

//if (0) echo a | else if (0) echo b | else if (1) echo works

//if (0) echo a | else { if (0) echo b } | else { if (1) echo doesn't work }

I'm sure you know that already, and your example code seems to imply this, just making it clear to those who don't.
Posted By: The_JD Re: /endif - 14/02/08 05:08 PM
Yeh, That's cool!
© mIRC Discussion Forums