On May 27, 2008, at 5:26 PM, Nick Zitzmann wrote:
On May 27, 2008, at 3:24 PM, Nathan wrote:

- (IBAction)operators:(id)sender {
        OB=[operatorBar floatValue];
        if (OB=1) {
                [operator setFloatValue: 4];
        }
        if (OB=2) {
                [operator setFloatValue: 5];
        }
}

So you would expect that if operatorBar = 1, then OB will = 1, and operator will = 4. I know the first part is ok due to testing, but what happens when I run the program is that it acts like the if's don't exist, so upon using operators method operator will equal 5 no matter what. What's wrong here?


In C, a single = is an assignment; a double == is a check for equality.

Yup, and an assignment expression (like OB=2) evaluates to the value that was assigned (in this caes, 2).

And conditionals in C treat 0 as false, and treat non-zero as true, which is why both of your ifs always evaluate to true.

--Andy

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to