Quote:Original post by Catafriggm
2 is better, because it has less comparisons, but if the compiler's halfway intelligent, it'll generate the same code either way.
And, because of this, you should choose whichever better describes the intent. For instance, if X can be "A", "B", or "C", then the first is probably clearer. If Y can be 1, 2, or 3, then the first is probably clearer. (If it turns out that the compiler doesn't optimize it
and profiling shows that this is a bottle neck, then switch it) If X and Y are limited to the values shown, then the second is probably clearer.