Re: note 8377 added to Control Structures

From: Date: Fri, 08 Sep 2000 23:04:48 +0000
Subject: Re: note 8377 added to Control Structures
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-4574@lists.php.net to get a copy of this message
jeffb@burst.com writes: > I have noticed that: > > if (($x != 'yes') || ($x != 'yeah')) > { > do some stuff > } > > does not work as expected. I had to break them apart into separate if statements. > > I realize switch will work for this, but it ends up being much more code than needed. > > http://www.php.net/manual/control-structures.php It works as expected for me--what behaviour were you looking for? What I expect from the above code is that the test should never fail. Reasoning: if $x == 'yes', then $x cannot be equal to 'yeah'; therefore, the second test succeeds. Since it's an OR, that means the whole expression succeeds. Similarly, if $x == 'yeah', it cannot be equal to 'yes', and the whole thing succeeds again. If $x == 'poodle', both tests succeed and the whole thing succeeds as well. I think you want '&&' where you have '||'. :) This'll make it so that 'do some stuff' only gets executed when $x is equal to neither 'yes' nor 'yeah'. Cheers, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.notes (#4574) next »