If - or statement help

Jones
Unregistered
 
Post: #1
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!
Quote this message in a reply
Moderator
Posts: 613
Joined: 2004.09
Post: #2
"||" 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

Kyle Richter
DragonForged.com
Twitter: @kylerichter
Quote this message in a reply
Moderator
Posts: 133
Joined: 2008.05
Post: #3
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
Quote this message in a reply
Moderator
Posts: 613
Joined: 2004.09
Post: #4
Woops yea it from an old habit of mine I inclose all statements in ()

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

Thanks for catching it =)

Kyle Richter
DragonForged.com
Twitter: @kylerichter
Quote this message in a reply
Jones
Unregistered
 
Post: #5
Ah yes, kodex the if (blah || blah2) was what I meant.

Thanks!

Heh, I kept trying to just writw in "or". Grin
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #6
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.
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #7
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 ||
Quote this message in a reply
zKing
Unregistered
 
Post: #8
What?!? Did they add an "or" keyword to C++?!? That'd be news to me.
Or is that a non-standard extention of XCode?
Quote this message in a reply
Member
Posts: 40
Joined: 2004.12
Post: #9
News to me too.

Jericho
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #10
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
Quote this message in a reply
zKing
Unregistered
 
Post: #11
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
Quote this message in a reply
Member
Posts: 41
Joined: 2006.01
Post: #12
Doesn't he mean the

#if

kind? He said it was for a header.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #13
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)
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Is this statement okay? NelsonMandella 3 2,520 Apr 30, 2009 03:07 PM
Last Post: Najdorf