ID:152677
 
Well, Its happened a few times to me, and now I don't even think I'm using it right anymore. XD
Whenever I have an if statement that uses ||, it works fine for one or two statements:
if(A == (B||C))

works fine.
if(A == (B||C||D||E||F||G))

Does not work fine. =\ If anyone wants to see the coding thats not working. (its basically the same thing, Just a little more complex.)

Is there a limit to how many "||"s you can do?
Mechanios wrote:
Well, Its happened a few times to me, and now I don't even think I'm using it right anymore. XD
Whenever I have an if statement that uses ||, it works fine for one or two statements:
> if(A == (B||C)) 
>

works fine.

Does it? That doesn't mean if A is B or C. It means if A is the first true value in B or C. That is, if B==4 and C==6, you're testing if A==4 only.

The correct usage is if(A==B || A==C).

Lummox JR
Well, first you have to look at what you're trying to do.

The || operator returns the first value that is true. So, if you do this:

var/a = 0
var/b = 4
var/c = 10

src << (a || b || c)


You'll get an output of 4, since it was the first thing found that was true. If what you're trying to do is return 1 if A is B or C, then you're on the wrong approach. If you want to check if A is B or C, then you have to check them seperatly.

if(A == B || A == C)
...


You can also use switch() and use commas to check values.

switch(A)
if(B, C)
...


~~> Unknown Person
well, I don't think || is supposed to be used in that way. I could be wrong, but I believe that it is supposed to be used as
if(A==B||A==C)


I could be wrong, but that is the way I always used it.
In response to Unknown Person (#2)
OHHHH! I see. So the way I've been doing it was all wrong. thanks for the much needed info. =D
In response to Mechanios (#4)
Might as well as my 2 cents:
You can also do this
if(A in list(B,C,D...))

.. or better yet:
if(!(A in list(B,C...)) return // ;/


- GhostAnime
In response to GhostAnime (#5)
That's a handy shortcut, but keep in mind it is slightly slower, as it needs to create and then garbage-collect a list just for that check.

I use it when I'm feeling lazy, in code that isn't time-critical. =)