Re: Can switch be used here?
Re: Can switch be used here?
- Subject: Re: Can switch be used here?
- From: Chas Spillar <email@hidden>
- Date: Mon, 24 Jul 2006 10:22:45 -0700
- Thread-topic: Can switch be used here?
If I remember correctly, a switch statement case must be a compiled time
integral value. That is, once the compilation is finished the value of the
case must be known. Thus, what you describe (using a boolean value) would
not work. If you can map the various boolean cases to match a single
integral value then it can be made to work. However, a laddered
if-then-else would be clearer.
E.g.
If (f==0) {
} else if (l = 0) {
} else if (f > l) {
} else if (f == l) {
} else if (f < l) {
}
Better would be to just subtract the two counts:
f - l
If the value is negative f is smaller than l, if the value is positive then
f is greater than l, if the value is 0 they are equivalent.
Chas.
> From: Brad Bumgarner <email@hidden>
> Date: Mon, 24 Jul 2006 11:13:21 -0600
> To: Cocoa-Dev Mail Cocoa-Dev Mail List <email@hidden>
> Subject: Can switch be used here?
>
> I have NSMutableSets f & l, each containing a variable number of
> items, including a possible none, and I want to do something based on
> which is larger, can I set this up using a switch statement?
> Something like (sudo code):
>
> switch (result)
> {
> case f = 0:
> do something;
> break;
> case l = 0:
> do something;
> break;
> case f > l:
> do something;
> break;
> case f == l:
> do something;
> break;
> case f < l:
> do something;
> break;
> }
>
> Or can I only accomplish this using if...then...else structures?
>
> Thanks,
> Brad Bumgarner, CTA
> _______________________________________________
> 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
_______________________________________________
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