If - or statement help
I was just trying to write my own header file when I realized..
I'd forgotten how to do an if - or statement!!
So I googled up three different tutorials, but none of them mentioned if-or!
So... can somebody tell me?
Thanks!
I'd forgotten how to do an if - or statement!!

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
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.
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 =)
ie: if ((Statement) || (statement2))
Thanks for catching it =)
Ah yes, kodex the if (blah || blah2) was what I meant.
Thanks!
Heh, I kept trying to just writw in "or".
Thanks!
Heh, I kept trying to just writw in "or".

Jones Wrote:Ah yes, kodex the if (blah || blah2) was what I meant.I believe you can write "or" too.
Thanks!
Heh, I kept trying to just writw in "or".
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 ||
What?!? Did they add an "or" keyword to C++?!? That'd be news to me.
Or is that a non-standard extention of XCode?
Or is that a non-standard extention of XCode?
News to me too.
Jericho
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
and, and_eq, bitand, bitor, compl, not, or, or_eq, xor, xor_eq, not_eq
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'
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'

Doesn't he mean the
#if
kind? He said it was for a header.
#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)
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
Is this statement okay? | NelsonMandella | 3 | 3,671 |
Apr 30, 2009 03:07 PM Last Post: Najdorf |