Questions tagged [switch-statement]
The switch-statement tag has no summary.
60 questions
19
votes
4
answers
51k
views
How is a switch statement better than a series of if statements? [duplicate]
Possible Duplicate:
Should I use switch statements or long if…else chains?
I'm working on a small program that will conduct an Insertion Sort. A number will be inputted through the keyboard ...
4
votes
3
answers
614
views
Is case after case in a switch efficient?
Just a random question regarding switch case efficiency in case after case; is the following code (assume pseudo code):
function bool isValid(String myString){
switch(myString){
case "stringA":
...
29
votes
7
answers
24k
views
Refactoring Switch Statements and is there any real use for Switch Statements at all?
I was reading this article and was wondering, do we get rid of all switch statements by replacing them with a Dictionary or a Factory so that there are no switch statements at all in my projects.
...
6
votes
2
answers
989
views
Good ways to jump to a particular state in a yielding stateful function?
I'm working on some embedded code using C. Various pieces of functionality need non-blocking stateful functions, which are mostly implemented using a switch on various states. For example, a modem ...
6
votes
3
answers
34k
views
How to use a switch statement with enum efficiently?
I would like to know how I can use a switch statement with enum values for the following scenarios:
I am making a small program for a flight reservation system. The program is meant to enter certain ...
15
votes
7
answers
17k
views
Appropriate uses of fall-through switch statements
When is it appropriate to use a fall-through (classic) switch statement? Is such usage recommended and encouraged or should it be avoided at all costs?
6
votes
2
answers
783
views
Patterns to avoid long switch block in UI?
Sometimes you have many entities which have common parts, but also should be addressed uniquely in UI. For example, in a CMS, you have many content types (like news, images, articles, pages, etc.) ...
7
votes
2
answers
6k
views
How is switch/case handled as to avoid comparisons to the case values?
I've read in multiple answers that switch/case avoids "unnecessary" comparisons, but I never learned this in college, and I'm a little stumped on how the program would figure out which case to jump to ...
63
votes
17
answers
38k
views
Why use an OO approach instead of a giant "switch" statement?
I am working in a .Net, C# shop and I have a coworker that keeps insisting that we should use giant Switch statements in our code with lots of "Cases" rather than more object oriented approaches. His ...
38
votes
10
answers
55k
views
Should I use switch statements or long if...else chains?
Often when I hear about the switch statement, its put off as a way to replace long if...else chains. But it seems that when I use the switch statement I'm writing more code that I would be just ...