Thread: && or ||

  1. #1
    Registered User
    Join Date
    Feb 2003

    && or ||


    Is it possible for someone to explain to me when using the boolen expressions && and || when each one should be used I keep making the mistake of using && when it should be || or vice and versa.


    if((answer > 5) && (answer <10))

    or is it

    if((answer > 5) || (answer <10))


  2. #2
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Your first if statement evaluate as true if variable answer is a number between 5 and 10.
    Second if statement is true for any numbe.

    || is ismilar to union and && to intersection.

    Check this (just for logic):

    - Micko
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  3. #3
    Registered User
    Join Date
    Feb 2003
    Thanks for your prompt reply

    I at least completely understand && now.

    Okay I am going to act dum however, it's only way I will finally understand this,

    Why would || be for any number?

    Thank you

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    You have ( cond1 || cond 2 ) as a single expression, which could be either true or false. What or ( || ) does is to say, "the expression is true when at least one of cond1 or cond2 is true, and false otherwise." Or, you could say, "the expression is true if cond1 is true, cond2 is true, or both are true, and false otherwise."
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    Registered User
    Join Date
    Feb 2003
    Right I understand


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  2. process killer on a loop
    By Anddos in forum Windows Programming
    Replies: 8
    Last Post: 01-11-2006, 01:50 AM
  3. Replies: 4
    Last Post: 11-23-2003, 07:15 AM
  4. Massive Function Problem
    By Marc Sharp in forum C Programming
    Replies: 10
    Last Post: 11-19-2003, 08:49 PM
  5. Tic Tac Toe Help
    By aresashura in forum C++ Programming
    Replies: 1
    Last Post: 11-21-2001, 12:52 PM