iDevGames Forums

Full Version: If - or statement help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Jones

I was just trying to write my own header file when I realized..

I'd forgotten how to do an if - or statement!! Wacko

So I googled up three different tutorials, but none of them mentioned if-or!

So... can somebody tell me?

Thanks!
"||" means Or, so
if (statement1) || (statement2)
will return true if either one are true
if (statement1) && (statement2)
will return true if only both are true

Or you could be talking about

if (statement1)
{}
else if (statement2)
{}
else
{}

Its kinda hard from your post to determine what you are asking for
Er, slight typo there kodex.

Your entire if statement should be within paranthesis itself.

Code:
if( statement1 || statement2)
true if either statement is true
if( statement1 && statement2)
true if both statements are true
if( a < 5 || a > 10)
true if a is less than 5 or a is greater than 10
if(a < 5 && a > 10)
never true
if(a >= 5 && a <= 10)
true if a is between 5-10
Woops yea it from an old habit of mine I inclose all statements in ()

ie: if ((Statement) || (statement2))

Thanks for catching it =)

Jones

Ah yes, kodex the if (blah || blah2) was what I meant.

Thanks!

Heh, I kept trying to just writw in "or". Grin
Jones Wrote:Ah yes, kodex the if (blah || blah2) was what I meant.

Thanks!

Heh, I kept trying to just writw in "or". Grin
I believe you can write "or" too.
skyhawk Wrote:I believe you can write "or" too.

Only if you're using C++. In C, you'd have to do this:

Code:
#define or ||

zKing

What?!? Did they add an "or" keyword to C++?!? That'd be news to me.
Or is that a non-standard extention of XCode?
News to me too.
It is actually part of standard C++. Here's a list of operators that have keywords associated to them in C++:
and, and_eq, bitand, bitor, compl, not, or, or_eq, xor, xor_eq, not_eq

zKing

Dang, just did some research on this. Sad to say I've been using C/C++ professionally for quite a while now (early 90's) and I haven't run into this before.

For those interested: look up ISO 646. Basically its an alternate international encoding of ASCII and its missing some important chars, so these key words were intended to overcome that limitation.

And there was a time where I was known as a C++-syntax-know-it-all. *sigh*
Pretty cool tho, always nice to learn a new 'trick' Wink
Doesn't he mean the

#if

kind? He said it was for a header.
He said it answered his question. Besides, he said he realized it when writing a header, not it was needed for the header. (and header doesn't mean that he'd be using macros)
Reference URL's