mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
#194915 14/02/08 03:18 AM
Joined: Mar 2006
Posts: 395
T
The_JD Offline OP
Pan-dimensional mouse
OP Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
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......


[02:16] * Titanic has quit IRC (Excess Flood)
The_JD #194916 14/02/08 03:23 AM
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

You may think it's self explanatory but it's not.

The_JD #194918 14/02/08 06:03 AM
Joined: Dec 2002
Posts: 503
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
The hell do you want 'endif'?

You structure an If correctly, and it's totally unnecessary!

The_JD #194922 14/02/08 07:10 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
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

genius_at_work #194933 14/02/08 02:19 PM
Joined: Mar 2006
Posts: 395
T
The_JD Offline OP
Pan-dimensional mouse
OP Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
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)
The_JD #194939 14/02/08 02:28 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
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
Riamus2 #194941 14/02/08 02:33 PM
Joined: Mar 2006
Posts: 395
T
The_JD Offline OP
Pan-dimensional mouse
OP Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
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'


[02:16] * Titanic has quit IRC (Excess Flood)
The_JD #194946 14/02/08 02:42 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
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
Riamus2 #194949 14/02/08 02:44 PM
Joined: Mar 2006
Posts: 395
T
The_JD Offline OP
Pan-dimensional mouse
OP Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
the if resets the else's?
*tests*


[02:16] * Titanic has quit IRC (Excess Flood)
The_JD #194951 14/02/08 02:47 PM
Joined: Mar 2006
Posts: 395
T
The_JD Offline OP
Pan-dimensional mouse
OP Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
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.

Last edited by The_JD; 14/02/08 02:48 PM.

[02:16] * Titanic has quit IRC (Excess Flood)
The_JD #194952 14/02/08 02:47 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.

Last edited by Riamus2; 14/02/08 02:48 PM.

Invision Support
#Invision on irc.irchighway.net
The_JD #194953 14/02/08 02:47 PM
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

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

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


RoCk #194954 14/02/08 02:49 PM
Joined: Mar 2006
Posts: 395
T
The_JD Offline OP
Pan-dimensional mouse
OP Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
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)
The_JD #194956 14/02/08 02:52 PM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
That'll teach you for learning VB. :P

-genius_at_work

genius_at_work #194960 14/02/08 02:57 PM
Joined: Mar 2006
Posts: 395
T
The_JD Offline OP
Pan-dimensional mouse
OP Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
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)
The_JD #194962 14/02/08 02:59 PM
Joined: Mar 2006
Posts: 395
T
The_JD Offline OP
Pan-dimensional mouse
OP Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
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)
The_JD #194964 14/02/08 03:03 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #194965 14/02/08 03:06 PM
Joined: Mar 2006
Posts: 395
T
The_JD Offline OP
Pan-dimensional mouse
OP Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
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


[02:16] * Titanic has quit IRC (Excess Flood)
The_JD #194969 14/02/08 03:18 PM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
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

genius_at_work #194970 14/02/08 03:20 PM
Joined: Mar 2006
Posts: 395
T
The_JD Offline OP
Pan-dimensional mouse
OP Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
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)
Page 1 of 2 1 2

Link Copied to Clipboard