1

How do you say if (A == 0) OR (B == 0)?

2
  • 1
    Jesus. The difference in complexity sure is big. Commented May 27, 2009 at 14:44
  • Compared to what? Prolog? Turtle? Cheese-strings? Quantum Chromodynamics? Commented May 27, 2009 at 15:18

4 Answers 4

15

Just to be snarky:

if (A === 0 || B === 0)
Sign up to request clarification or add additional context in comments.

2 Comments

Now all you have to do is change your name from "Coehoorn" to "Coercion" ;)
Actually, that's a good point. Without the strict check for equality, all kinds of falsy values count as zero. If we're going to be lax, might as well just do if !(A && B)
10
if (A == 0 || B == 0) 

or

if ((A == 0) || (B == 0)) 

Check out Control Structures and Operators on Wikibooks

Comments

8
if (  A == 0  ||  B == 0 ) {
}

1 Comment

I've faced this dilemma before; what I did was give the best answer a checkmark (15pts) and the rest of them that were almost as good +1s.
6

depends if you mean exclusive or inclusive OR :)

Inclusive OR:

if(A == 0 || B == 0) 
{ 
}

Exclusive OR:

if(A == 0 && B != 0 || A != 0 && B == 0) 
{ 
}

2 Comments

Actually a simpler xor can be achieved by if(!A != !B) but perhaps readability suffers. JS also has a native bitwise xor in ^ where that applies.
annakata: Why not (A != B). It will give the same truth table as (A==0 XOR B==0).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.