henesua wrote...
So... while the constants
TRUE = 1
and
FALSE = 0
When you evaluate a statement, it seems to me that evaluating a statement as true is different.
Its pretty clear to me that the following always evaluates as true
int x=8;
if(x)
return TRUE;
else
return FALSE;
but what about checking for false?
The reason I ask is that some functions return -1 on error instead of 0. And I was wondering if all values less than 1 would evaluate as FALSE.
I am going to expand on what Shadow already stated.
First lets look at the comparison
operators and expand on them a lillte.
They are in fact
operators and as
operators the can be used any where that
operators can be used at.
As an Example lets when giving 500 xp to a character i wanted to give then an extra 50xp if they where first level. with the "Bonus". I would not even have to use an If statment, Since the '==' is an operator that returns 1 or 0. (TRUE or FALSE). I could evalulate it like this.
int nXP = 500 + (GetHitDice(oPC)== 1)* 50;
If the PC has only one level then GetHitDice(oPC)== 1 evalulates to 1 and the 50 gets added. // 1*50 = 50;
If they are not first level then the GetHitDice(oPC)== 1 evelaulates to 0 and the 50 does not get added. // 0 * 50 = 0.
Note: the Above is leagle to do it just breaks convention
**********
Ok the If statment:
If (Expresion) ...
The Expresion is anything that evalulates to an intenger.
Now the Expresion is never checked to see if it is TRUE or not. It is only checked for if it is FALSE. If it is FALSE(0) the execution order Jumps over the code placed in the TRUE bracket. If it is not false then no jump is taken and the code excution falls through to the TRUE case.
In short the only thing that matters is if you expression is Zero or Not Zero.
If ( Expression)
{
// Code excuted if the Expression !=0
}
else
{
// Code excuted if the Expression == 0
}
*****
with all that said the if statment you posted above.
int x=8;
if(x)
return TRUE;
else
return FALSE;
would be the same thing as.
return x != 0; // Returns FALSE if x is zerp, Returns TRUE for everything else;
Hope that helps.