If Then Statments

• 05-20-2002
If Then Statments
I don't understand IF, THEN statments and also I don't get the Boolean operators OR, NOT, and AND.

I've read the turtorial about them but I just don't understand them and i don't get this:

A. !(1 || 0) ANSWER: 0
B. !(1 || 1 && 0) ANSWER: 0 (AND is evaluated before OR)
C. !((1 || 0) && 0) ANSWER: 1 (Parenthesis are useful

• 05-20-2002
quzah
Re: If Then Statments
Quote:

I don't understand IF, THEN statments and also I don't get the Boolean operators OR, NOT, and AND.

I've read the turtorial about them but I just don't understand them and i don't get this:

A. !(1 || 0) ANSWER: 0
B. !(1 || 1 && 0) ANSWER: 0 (AND is evaluated before OR)
C. !((1 || 0) && 0) ANSWER: 1 (Parenthesis are useful

What's not to understand? There is no "THEN" in C.

if ( this_is_non_zero ) /* then do something */

Thus:

a OR b == If 'a' or 'b' is non zero, then...
!( a OR B) == reverse the answer from the "a or b" comparison.

SO, in this case, since 1 is one, then the OR comparison is true. Since you reverse the answer, it becomes false.

Anything "AND ZERO" is false. Thus, it goes to reason, that the opposite of zero is true, so the "!( .. AND ZERO )" will equate to true.

Quzah.
• 05-20-2002
So basicly...

!(1 OR 0) wouldn't the answer be 1 OR 0 ? why is it 0 ?

In here:
!(1 || 1 && 0) ANSWER: 0 (AND is evaluated before OR)

thus AND (&&) is evaluated after OR (||)

and this one:
!((1 || 0) && 0) ANSWER:1 ..... I don't get at all..

is there maybe another turtorial so i could understand it more?
• 05-20-2002
Hammer
You do realise that the exclamation mark is used to reverse the result? So

Quote:

!(1 OR 0) wouldn't the answer be 1 OR 0 ? why is it 0 ?
We start with 1 OR 0, which equates to 1. Then it's reversed using the ! symbol, so the answer is 0.

Apply this to the others and see if you understand better.

! is a NOT symbol, btw.
• 05-20-2002
Thanks Hammer, I didn't realised that "!":D now you got me starting to get these things but what about the other one:

!((1 || 0) && 0) ANSWER:1

• 05-20-2002
Hammer
Quote:

!((1 || 0) && 0) ANSWER:1
- (1 || 0) means 1 OR 0, result: 1

so now it looks like this

>!(1 && 0)

Now we go
- 1 && 0 means 1 AND 0, result: 0

so now it looks like this

>!(0)

This means NOT (0), result: 1

Remember the brackets restrict and control the order in which things happen.
• 05-20-2002