Skip to main content

Questions tagged [switch-statement]

In computer programming, a switch, case, select or inspect statement is a type of selection control mechanism used to invoke specific blocks of code based on variable contents.

1 vote
1 answer
33 views

_Generic Statement For An Enumerator (Enum)?

I frequently have to deal with the functionality of enums in C. However, there doesn't seem to be an easy & equally efficient way of supplying a different result based off of a predefined enum ...
0 votes
1 answer
50 views

Switch expression vs switch statement which one to use [closed]

Java 14 standardized switch expression and since Java 17 they have enhanced the switch expression to include pattern matching. Is there any guideline to when one should be using switch statement vs ...
10 votes
6 answers
50k views

In a switch case statement, it says "duplicate case value" comes up as an error. Anyone know why?

I am working on a rock paper scissors program, but this time the computer chooses rock half the time, scissors a third of the time, and paper only one sixth of the time. The way I did this was I ...
367 votes
30 answers
431k views

Is it possible to use the instanceof operator in a switch statement?

I have a question of using switch case for instanceof object: For example: my problem can be reproduced in Java: if(this instanceof A) doA(); else if(this instanceof B) doB(); else if(this ...
-1 votes
1 answer
60 views

Write a method that takes 3 integer as parameters, return true if they are equal, return false otherwise without using if statement [closed]

I am trying to write a method that compares three integers without using the if statement. I tried the switch statement, but it wouldn't work. Eclipse shows case expressions must be constants. Here is ...
0 votes
2 answers
40 views

Utilizing array items as an entire case in a switch statement

I would like to generate cases in a switch statement from an array. Here is how the array is generated: pointObjects = []; for (var i = 0; i < 2; i++) { // Generate cases. var url; var ...
274 votes
21 answers
145k views

Is there any significant difference between using if/else and switch-case in C#?

What is the benefit/downside to using a switch statement vs. an if/else in C#. I can't imagine there being that big of a difference, other than maybe the look of your code. Is there any reason why the ...
-3 votes
2 answers
67 views

How can I use a modified String in a C# switch → case statement?

I have a string I need to use, a variant of, in many places throughout my application. For example: String myString = "The Quick Brown Fox"; string someLowerCaseString = myString.ToLower(); ...
110 votes
5 answers
207k views

Switch case on type c# [duplicate]

I get a big if/else on class type. Is there a way to do it with a switch case? Example: function test(object obj) { if(obj is WebControl) { }else if(obj is TextBox) { } else if(obj is ComboBox) { } ...
28 votes
1 answer
45k views

switch case in XSL

I have a loop with the same tags to load content in ten cells but has a difference div title and background image, so I wonder is there any way to use the switch case just to put correct div title ...
0 votes
0 answers
11 views

On R Identify when a qualitative variable changes from one value to another

On the x-axis I have dates and for each date I have a qualitative variable (colour). I would like to create on R a new df with the date on which my variable changes (e.g. the date from which I turn ...
0 votes
6 answers
284 views

How to properly use C switch statement

I have a code snippet that I am using to learn some C char* input( char *s ){ scanf("%[^\n]%*c",s); return s; } void main() { printf("Welcome to a string input/output example written in C!...
0 votes
0 answers
7 views

QtCreator: missing shortcut for switching between widgets

For example (in QtCreator) using Ctrl-F to find a piece of text in the opened file – the focus switches from files to search box, I enter the searched text, I enter ENTER, and if existent, the file ...
2 votes
3 answers
3k views

How do I safely fix ESLint`no-fallthrough` error for intentional switch case ommissions of break/return/throw?

For my application, I want to use a switch case pattern. Some cases require OR logic, which means that there are intentional fallthroughs in the code for brevity. However, ESLint doesn't like that and ...
0 votes
1 answer
35 views

What is the best way to have different entry points for a list of iterative commands?

I have a list of iterative Python commands: def command_list(start_at): step1 step2 step3 # ... stepN Now I want to start_at different steps in this list of commands and then ...

15 30 50 per page
1
2 3 4 5
788