Skip to main content

Questions tagged [switch-statement]

-1 votes
1 answer
13 views

The reason I wanted to ask is because of some code from Undertale that is responsible for choosing which dialogue set to use. It works something like this: switch (id) { case 0: msg[0] = &...
Bunabyte's user avatar
  • 641
2 votes
3 answers
977 views

I know there are already some questions about replacing if else with polymorphism, for example: Applying Replace Conditional with Composition in functional programming Is it wrong to use any type of ...
wcminipgasker2023's user avatar
0 votes
1 answer
86 views

I have the following code in C that reads data off a char array and makes decisions on what variables should some pointers point to. char preset1[20]; char preset1Name[20]; int preset1Temp; int ...
HFOrangefish's user avatar
3 votes
2 answers
861 views

It is said that visitor pattern is applicable to problems where objects rarely change but we add actions on those objects more frequently. What if the objects are changing too though? For example we ...
Ehsan Poursaeed's user avatar
1 vote
2 answers
1k views

I am practicing design patterns and OO concepts such as inheritance in java and I'm writing an application that represents a vending machine. I have two questions focused on ideal structure and design ...
Bob Jones's user avatar
28 votes
7 answers
8k views

This doubt is about Switch Statements from Chapter 3: Functions of the book named Clean Code Here we have a function: public Money calculatePay(Employee e) throws InvalidEmployeeType { switch (e....
The Chinky Sight's user avatar
2 votes
2 answers
1k views

Essentially I've got a bunch of formulas in two giant methods in a class designed to do math transformations and evaluations to multiple inputs. Where the inputs are actually lists of inputs (as there ...
Akumaburn's user avatar
  • 131
0 votes
1 answer
666 views

I have been using a pattern in a lot of places (mainly C#) that I would like to know the name of. Here is an example of it in C#: public enum ThingType { A, B, C } public interface ...
Romen's user avatar
  • 111
11 votes
5 answers
4k views

I sometimes end up with services encapsulating the responsibility of doing some sort of business process for which there are several possible outputs. Typically one of those output is success and the ...
Enrico Massone's user avatar
5 votes
4 answers
35k views

In my class I have a processor manager that contains a switch case. I have just changed the real name values to Ant, Parrot and Snake. switch (name) { case "ant": return new ...
Bastien Vandamme's user avatar
7 votes
6 answers
13k views

As a practice I'm working on a CPU simulator (runs at about 1.78MHz) and I'm using a switch statement to execute correct opcodes based on the value in the IR (instruction register) variable. This ...
NMITIMEN's user avatar
  • 119
2 votes
2 answers
550 views

Traditional switch blocks have one scope, so the following throws a compiler error "A local variable or function named 'message' is already defined in this scope": switch(value) { case 1: ...
rory.ap's user avatar
  • 929
1 vote
4 answers
1k views

Backstory (You can skip) I am writing a pronunciation library for irregular words. Take something like the following: T1E1s // tee one E one es | tee one E ones 1994-1995// 1994 (minus|dash|to|) ...
Anon's user avatar
  • 3,649
47 votes
12 answers
21k views

I have a switch structure that has several cases to handle. The switch operates over an enum which poses the issue of duplicate code through combined values: // All possible combinations of One - ...
Taco's user avatar
  • 1,175
-1 votes
2 answers
1k views

I was wondering if there is a way to get the values of every case in a switch statement? When you provide a not implemented case, I would like to throw some exception and provide a list of available ...
Lubomir Stoimchev's user avatar

15 30 50 per page