noobish question regarding using "or"

This is a discussion on noobish question regarding using "or" within the C++ Programming forums, part of the General Programming Boards category; alright, as the title implies, this is a pretty noobish question. I can't figure out how to use "OR" statements ...

  1. #1
    n3v
    n3v is offline
    irregularly symmetrical n3v's Avatar
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    67

    noobish question regarding using "or"

    alright, as the title implies, this is a pretty noobish question. I can't figure out how to use "OR" statements in an if statement. for some reason, every way i try it, it fails. then again, i'm probably an idiot. I do something like this:

    Code:
    if (num1 || num2 == 9) {
    and it never works. enlightment would be ever-so enlightening.
    thanks.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    if( num1 == 9 || num2 == 9)

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    135
    Quote Originally Posted by n3v
    alright, as the title implies, this is a pretty noobish question. I can't figure out how to use "OR" statements in an if statement. for some reason, every way i try it, it fails. then again, i'm probably an idiot. I do something like this:

    Code:
    if (num1 || num2 == 9) {
    and it never works. enlightment would be ever-so enlightening.
    thanks.
    See, You're misunderstanding how this works. You think it does the following:

    IF num1 == 9 || IF num2 == 9

    which is not the case, it actually does this:

    IF num2 == 9 ( and, *only* if false, will also do: ) || IF num1 (is not false)

    So num1 is only being tested against itself, if it's zero or not, while num2 is actually being tested against 9.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

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