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.

03-22-2006

7stud

if( num1 == 9 || num2 == 9)

03-22-2006

xeddiex

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.