Jump to content

Archived

This topic is now archived and is closed to further replies.

AV1611

ELSEIF

Recommended Posts

Question:

If I do a clause like this:

IF a...
elseif b...
else c...

and a, b, and c are ALL true,

Does it do a, then ignore b & c?

I need it to do only the first true it find, not all of them...

Thanks.

Share this post


Link to post
Share on other sites
Yes. [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Share this post


Link to post
Share on other sites
yes, because elseif implies that the if was FALSE. else implies that the if (or elseif) was FALSE.

if (if this is true) {
do this
} elseif (since the above was not true, check if this is true. if it is true) {
do this
} else {
since the above was not true, do this
}

the difference between elseif and else is that else will be executed no matter what, if the if is false, whereas the elseif will only be executed if the if is false and the elseif is true. but elseif and/or else will not be executed if the if is true.

Share this post


Link to post
Share on other sites
[!--quoteo(post=381549:date=Jun 8 2006, 08:09 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Jun 8 2006, 08:09 PM) [snapback]381549[/snapback][/div][div class=\'quotemain\'][!--quotec--]
the difference between elseif and else is that else will be executed no matter what, if the if is false, whereas the elseif will only be executed if the if is false and the elseif is true. but elseif and/or else will not be executed if the if is true.
[/quote]

I think I preferred Poirot's answer :-)

Share this post


Link to post
Share on other sites
i give you a cookie if you say it three times fast [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]

Share this post


Link to post
Share on other sites
LOL

YES...that was the answer I was looking for...

I just wanted to make sure I didn't need to add some safety net, because I am doing a script that would be devastating if the ELSE executed after the IF had already executed...

:X

Share this post


Link to post
Share on other sites
It was easily verifiable by adding an echo statement in each of the if/elseif bits.

Share this post


Link to post
Share on other sites
Yea, I thought of that after I had already done this thread :?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.