If Then Statments

This is a discussion on If Then Statments within the C Programming forums, part of the General Programming Boards category; I don't understand IF, THEN statments and also I don't get the Boolean operators OR, NOT, and AND. I've read ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    8

    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

    Can someone please help me out with this?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: If Then Statments

    Originally posted by BladeBoss2
    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

    Can someone please help me out with this?

    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.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    8
    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?

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You do realise that the exclamation mark is used to reverse the result? So

    !(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.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    8
    Thanks Hammer, I didn't realised that "!" now you got me starting to get these things but what about the other one:

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

    Blade

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    !((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.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    May 2002
    Posts
    8

    Thumbs up

    Thanks Hammer, I finally get this

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. If statments using char variable, need help
    By pandapwnage in forum C++ Programming
    Replies: 20
    Last Post: 10-01-2005, 03:33 PM
  2. Not, Or, And statments
    By CompiConQuiso in forum C++ Programming
    Replies: 3
    Last Post: 03-08-2005, 04:27 PM
  3. True or false statments used in my return...
    By correlcj in forum C++ Programming
    Replies: 5
    Last Post: 10-06-2002, 04:26 PM
  4. Case statments with long strings... is it possible?
    By Unregistered in forum Game Programming
    Replies: 4
    Last Post: 06-21-2002, 11:22 PM
  5. if statments
    By JPed2003 in forum C++ Programming
    Replies: 8
    Last Post: 05-10-2002, 07:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21