I'm looking through the new code that I've inherited and getting to know and
love it and I'm running across a few new circumstances I've never seen before.
With that said, I just noticed a switch statement with empty case conditions
where the variable being checked will be 0, and the execution point/program
counter hits both the case statement for 0 and for 1.
It looks something like this:
switch (myObject.myInt) {
case 0:
{
// There is no code at all within these parens. This is empty.
}
case 1:
{
// Important stuff happens here
}
break;
case 2:
{
// More important stuff happens here
}
break;
default:
break;
}
I was really surprised as all our code within case 1 was getting executed when
myInt == 0 and when myInt == 1. Then I noticed that case:0 was put in for a
placeholder condition. Since it was entered as a placeholder, it was entered
without a break statement after it. In the case of myInt == 0, the program
execution just continued down into the case of 1 code block and happily
executed it.
Who says learning new code isn't fun?
Cheers,
Alex
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]