Jump to content


Photo

ELSEIF


  • Please log in to reply
7 replies to this topic

#1 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 08 June 2006 - 06:08 PM

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.

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 08 June 2006 - 06:41 PM

Yes. [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
~ D Kuang

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 08 June 2006 - 07:09 PM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 08 June 2006 - 08:23 PM

[!--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) View Post[/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 :-)
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 08 June 2006 - 08:45 PM

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\" /]
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 08 June 2006 - 09:14 PM

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



#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 09 June 2006 - 12:15 AM

It was easily verifiable by adding an echo statement in each of the if/elseif bits.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 09 June 2006 - 03:22 PM

Yea, I thought of that after I had already done this thread :?





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users