Skip to main content

Questions tagged [switch-statement]

Filter by
Sorted by
Tagged with
19 votes
4 answers
51k views

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 ...
kullalok's user avatar
  • 1,085
4 votes
3 answers
614 views

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": ...
RandomGuy's user avatar
  • 222
29 votes
7 answers
24k views

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. ...
Kanini's user avatar
  • 2,258
6 votes
2 answers
989 views

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 ...
bryhoyt's user avatar
  • 161
6 votes
3 answers
34k views

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 ...
Maxood's user avatar
  • 1,493
15 votes
7 answers
17k views

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?
shabunc's user avatar
  • 2,464
6 votes
2 answers
783 views

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.) ...
Saeed Neamati's user avatar
7 votes
2 answers
6k views

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 ...
Michael's user avatar
  • 483
63 votes
17 answers
38k views

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 ...
James P. Wright's user avatar
38 votes
10 answers
55k views

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 ...
TheLQ's user avatar
  • 13.7k