How do you say if (A == 0) OR (B == 0)?
-
1Jesus. The difference in complexity sure is big.ralphtheninja– ralphtheninja2009-05-27 14:44:04 +00:00Commented May 27, 2009 at 14:44
-
Compared to what? Prolog? Turtle? Cheese-strings? Quantum Chromodynamics?annakata– annakata2009-05-27 15:18:29 +00:00Commented May 27, 2009 at 15:18
Add a comment
|
4 Answers
Just to be snarky:
if (A === 0 || B === 0)
2 Comments
Eoin Campbell
Now all you have to do is change your name from "Coehoorn" to "Coercion" ;)
Nosredna
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)
if (A == 0 || B == 0)
or
if ((A == 0) || (B == 0))
Check out Control Structures and Operators on Wikibooks
Comments
if ( A == 0 || B == 0 ) {
}
1 Comment
Jason S
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.
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)
{
}