# Thread: OR statement in C

1. ## OR statement in C

Hi,

Is there such a thing as an OR statement in C?

For example:

If (x>0 OR x<10)
then.....

Thanks!

2. Yes, replace the OR with || (AND is && in C)

3. Thank you!

4. No problem, I'll bill you later.

5. Keylac, I assume you are a beginner (so am I). Pay attention to the double symbols: && and ||

You also have the single | and &, which are the bitwise operators for or and and.

You'll remember from boolean logics:

0 | 1 = 1
1 | 0 = 1
1 | 1 = 1
0 | 0 = 0

0 & 1 = 0
1 & 0 = 0
1 & 1 = 1
0 & 0 = 0

It's an often made beginner's mistake to confuse these operators (logical and bitwise), it 's comparable to

if (x = 0)

6. another thing ....

x=6 is often mistaken with x ==6.

x = 6 means, make x equal 6.

x == 6 means, "Is x equal to 6?"

7. Originally Posted by x2x3i5x
another thing ....

x=6 is often mistaken with x ==6.

x = 6 means, make x equal 6.

x == 6 means, "Is x equal to 6?"
I totally agree with this point, and this is a very good point to mention where most beginner does the mistake. in condition or loop people say something like x=6 means it will, always be true.

so to reduce what we can do just

do like this

Code:
`if (6 ==x)`
Then when ever by mistake we do like

Code:
`if (6 =x)`
it means the compiler will say than
error: lvalue required as left operand of assignment
In my point of view we can do like this also

8. ## Thanks!

Thanks everyone for the great info!

9. Okay, now that you got the important, here's some fun trivia:

If your compiler supports the 1999 edition of the C standard sufficiently, you can #include <iso646.h> and use the or macro instead of ||. (<iso646.h> defines or to be || for you.) That said, there is probably no benefit for you in doing this.