FROM : Chas Spillar
DATE : Mon Jul 24 19:22:45 2006
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 <b.<email_removed>>
> Date: Mon, 24 Jul 2006 11:13:21 -0600
> To: Cocoa-Dev Mail Cocoa-Dev Mail List <<email_removed>>
> 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_removed>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
DATE : Mon Jul 24 19:22:45 2006
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 <b.<email_removed>>
> Date: Mon, 24 Jul 2006 11:13:21 -0600
> To: Cocoa-Dev Mail Cocoa-Dev Mail List <<email_removed>>
> 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_removed>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
| Related mails | Author | Date |
|---|---|---|
| Brad Bumgarner | Jul 24, 19:13 | |
| Chas Spillar | Jul 24, 19:22 | |
| Brad Bumgarner | Jul 24, 19:28 |






Cocoa mail archive

