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.
switch-statement
11,802
questions
1
vote
1
answer
34
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 ...
-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 ...
-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();
...
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
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 ...
0
votes
1
answer
51
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 ...
1
vote
1
answer
39
views
Why those two switch blocks are not equivalent?
enum Foo {
bar,
baz,
}
By just simply looking at this code, I thought it would print bar, baz and then barr, bazz
void main() {
final f = Foo.bar;
switch (f) {
case Foo.bar:
case Foo....
0
votes
0
answers
30
views
Trouble Testing Error Handling in Next.js Component with TypeScript and Vitest
Environment:
"next": "14.2.3",
"vitest": "1.6.0",
"@testing-library/jest-dom": "6.4.5",
I'm trying to write tests for a Next.js component ...
2
votes
1
answer
99
views
Is There a Pragmatic Solution to Remove Enum Switches?
The title of this question is a little strange-sounding, but I could think of no better way to word it. My problem is this; I have a type inside a project called AmbiguousType, which is a union in ...
-1
votes
1
answer
40
views
Is there a tool or specific syntax to insert cases into switches with consecutive indices and make the indices below adjust
I have a function that takes an integer and returns a string that is picked by a switch. The strings are part of a coherent text and I want to be able to add cases to the switch whenever I want to ...
0
votes
1
answer
47
views
Is there a reason an execute pipeline cannot work in a switch activity?
I have a pipeline that has a switch activity - Quite simply, one of the paths is to run an execute pipeline.
I know the path works if I put a Wait in there only but if I put an execute pipeline, the ...
0
votes
1
answer
69
views
Which is better in this scenario - if else loop or case in shell scripting?
I am trying to write a shell script which has a part where I have to use some kind of loop to execute some commands if condition satisfy.
I want to understand what is the best way to approach this ...
0
votes
1
answer
96
views
Should switch-statement in C++ be used for checking user character input
I am following C++ Programming language book and came upon code similar to one below:
bool acceptSwitchWithRetry()
{
int tries = 0;
while (tries < 4) {
cout << "Do you ...
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 ...