Re: Inside or outside an if statement - what's the difference?
Re: Inside or outside an if statement - what's the difference?
- Subject: Re: Inside or outside an if statement - what's the difference?
- From: James Bucanek <email@hidden>
- Date: Thu, 29 Sep 2005 07:59:51 -0700
Ian Jackson wrote on Thursday, September 29, 2005:
>It seems to suggest there's something
>I'm totally not getting about what goes on with if statements.
There's nothing mysterous about an if statement. They are probably C's most basic construct.
You obviously have a bug in your program. Set a break point at the if statement. When your application stops at that point, examine the variable that make up 'meetConditions'. Use the Step command in the debugger. If the debugger moves into the block, then the conditional expression evaluated to true (non-zero). If it skips over the block, then your condition expression evaluated to false (zero). If you want to watch this happen, assign the expresstion to an intermediate variable so you can see the results of the conditional expression:
in meetsCondition = ( ... your conditional statement ... )
if (meetsCondition)
{
...
}
It sound like you're new to C, so I'll point out a number of pitfalls that catch newbie C programmers:
1) Make sure you didn't code an assigement (any C statement can be an assignement).
if ( a == 1 ) // true iff a equals 1
if ( a = 1 ) // always true: 1 is assigned to a, and the result of the expr is always 1
if ( a <= 1 ) // true iff a is less than or equal to 1
if ( a <<= 1 ) // a is shifted one bit to the left, true if a is non-zero
2) Every expression is an integer
if ( 0 < a < 5 ) // this is a valid C expression, but will always be true
// it evaluates to (0<a) < 5 that reduces in either 0<5 or 1<5
3) != is not =!
if ( a =! b ) // this evaluates to a = (!b)
4) Understand the difference between bitwise and logical operators. & and && are not the same and have different orders of evaluation.
... and there are about a hundred more.
--
James Bucanek
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden