Is there an or condition like...
if(thesky = "blue" or "red")
Plz tell me I always thought it was || but I found it doesn't work like I want it. || = (true value if either A or B is nonzero; false value otherwise )
ID:161206
Jun 3 2008, 6:06 pm
|
|
Jun 3 2008, 6:13 pm
|
|
In response to Popisfizzy
|
|
thanks.
|
In response to Popisfizzy
|
|
For the former, wouldn't this work as well?
if(thesky == ("blue" || "red")) |
In response to Darkmag1c1an11
|
|
Darkmag1c1an11 wrote:
For the former, wouldn't this work as well? > if(thesky == ("blue" || "red")) No, that wouldn't work. The string expressions in the bracket would evaluate as true, since it is not a false boolean value (which are 0, null or empty string ""). This is what the compiler thinks in your example: if(thesky == ("blue" || "red")) What could work, if each value of that variable does something different, is switch() |
In response to GhostAnime
|
|
GhostAnime wrote:
This is what the compiler thinks in your example: if(thesky == ("blue" || "red")) Not entirely, you make it seem as though it checks if thesky actually equals 1, when it would only be checking if it is a true value (not 0, not null). Hence simplifying both sides of the expression might be more accurate: if(thesky == ("blue" || "red")) |
In response to Kuraudo
|
|
Kuraudo wrote:
Hence simplifying both sides of the expression might be more accurate: Actually, checking something for being TRUE or FALSE is just checking for it to equal 1 or 0, respectively, since those are just macros for those values (not all too useful, aren't they). Also, the illustration with 1's coming out of nowhere is quite misleading anyway. Besides, it would actually work quite different from what you people said. if(thesky == ("blue" || "red")) is going to be equivalent to if(thesky == "blue"); look up the || operator. It is a useful feature of it. |
In response to Kaioken
|
|
Kaioken wrote:
Kuraudo wrote: You missed the whole point. I know it was checking for 1 or 0, but I applied it to both sides of the expression, not just one, hence the part you quoted. |
In response to Kuraudo
|
|
Kuraudo wrote:
You missed the whole point. I know I've definitely missed you guys' point here, because- I know it was checking for 1 or 0, Nowhere is the code here actually checking for 1, or 0, I'm not sure what's that all about. Sure, GhostAnime was wrong before you, but if you're going for an accurate illustration it would be something like this: if( Var == ("yes" || "no") ) |