|
Joined: Mar 2006
Posts: 396
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Mar 2006
Posts: 396 |
Well the title is quiet obvious. /endif (I think its self explanatory). at the moment, I find myself having to do this too often: if (1) {
if (Blah) { dothis }
else { dothat }
}
if (1) {
if (blah2) { dothis......
[02:16] * Titanic has quit IRC (Excess Flood)
|
|
|
|
Joined: Dec 2002
Posts: 2,033
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,033 |
You may think it's self explanatory but it's not.
|
|
|
|
Joined: Dec 2002
Posts: 503
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 503 |
The hell do you want 'endif'?
You structure an If correctly, and it's totally unnecessary!
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
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
|
|
|
|
Joined: Mar 2006
Posts: 396
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Mar 2006
Posts: 396 |
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.
Last edited by The_JD; 14/02/08 02:20 PM.
[02:16] * Titanic has quit IRC (Excess Flood)
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
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.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Mar 2006
Posts: 396
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Mar 2006
Posts: 396 |
basically, this will not work if (1) echo hi
else echo byte
if (2) echo hello
else echo see ya! This will: 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'
[02:16] * Titanic has quit IRC (Excess Flood)
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Your first example would work fine. Any IF following an ELSE will act as if the previous IF/ELSEIF/ELSE wasn't there.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Mar 2006
Posts: 396
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Mar 2006
Posts: 396 |
the if resets the else's? *tests*
[02:16] * Titanic has quit IRC (Excess Flood)
|
|
|
|
Joined: Mar 2006
Posts: 396
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Mar 2006
Posts: 396 |
wow, It does work *CANCEL THAT REQUEST!!!* Thanks Riamus. Code i used: 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.
Last edited by The_JD; 14/02/08 02:48 PM.
[02:16] * Titanic has quit IRC (Excess Flood)
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Well... reverse that -- The ELSE "resets" the IFs.  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.
Last edited by Riamus2; 14/02/08 02:48 PM.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Dec 2002
Posts: 2,033
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,033 |
But the first one does work. Did you test any of this or just assuming?
~ Edit ~ I tried to delete but was too late.
|
|
|
|
Joined: Mar 2006
Posts: 396
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Mar 2006
Posts: 396 |
I just assumed, due to common logic. I would not expect it to be reset without endif
[02:16] * Titanic has quit IRC (Excess Flood)
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
That'll teach you for learning VB. :P
-genius_at_work
|
|
|
|
Joined: Mar 2006
Posts: 396
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Mar 2006
Posts: 396 |
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
[02:16] * Titanic has quit IRC (Excess Flood)
|
|
|
|
Joined: Mar 2006
Posts: 396
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Mar 2006
Posts: 396 |
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?
Last edited by The_JD; 14/02/08 03:00 PM.
[02:16] * Titanic has quit IRC (Excess Flood)
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Technically speaking, an ELSEIF is really just an ELSE followed by a "nested" IF.
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.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Mar 2006
Posts: 396
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Mar 2006
Posts: 396 |
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 
[02:16] * Titanic has quit IRC (Excess Flood)
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
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
|
|
|
|
Joined: Mar 2006
Posts: 396
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Mar 2006
Posts: 396 |
Thanks!!! I think this topic is answered now lol (and I feel like a took tool).
Last edited by The_JD; 14/02/08 03:21 PM.
[02:16] * Titanic has quit IRC (Excess Flood)
|
|
|
|
|