>> (Personally I dislike switch statements.) > > Why? Do I need a reason? ;-)
Well, okay, here are a few: - You have to remember to put in break statements, which are really disguised gotos. - Leaving out a break statement unintentionally causes a bug, due to fall-through. It does happen, especially with newcomers. - Omitting a break statement intentionally in order to fall through to the next case is tricky and non-obvious code IMO. It can also lead to bugs if someone spots the "missing" break and inserts it, or if the order of the cases is changed for some reason, or if a new case is inserted. Asking for trouble. - Switches test equality of integer values, whereas ifs can test any requirement that can be reduced to a boolean expression. Which is almost everything. Enough to be going on with! As for efficiency, if that were really important we'd all be coding in assembler and using jump tables instead of switches. Let the machines do a bit of work, I say. That's what they're there for, to make our lives easier! David
