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 ...
Zenais's user avatar
  • 96
-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 ...
Sơn Trần's user avatar
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 ...
throwaway2908457's user avatar
-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(); ...
Brian's user avatar
  • 1,909
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 ...
Pauline Lefranc's user avatar
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 ...
joerngr's user avatar
  • 111
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 ...
JustACoder's user avatar
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....
TSR's user avatar
  • 19.4k
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 ...
pop's user avatar
  • 109
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 ...
Zenais's user avatar
  • 96
-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 ...
user3808217's user avatar
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 ...
Embark6655's user avatar
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 ...
abssyz's user avatar
  • 15
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 ...
DannyBoy's user avatar
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 ...
Sur3's user avatar
  • 31
0 votes
0 answers
9 views

Data corruption problem of using VirtioBlk driver in custom operating system on RISC-V

During the kernel initialization phase, I am able to read data correctly from the boot sector using the VirtioBlk driver. The data read at this stage is as expected. However, after the kernel performs ...
user25279082's user avatar
0 votes
0 answers
10 views

PHP, 2 different interpretations for the same evaluation using if and switch case [duplicate]

in the following code, does anyone know why is the $val === 0  case never running when there's a zero in the $arr array? <?php function plusMinus($arr) { $positiveCount = $zeroCount = $...
eliasdev's user avatar
0 votes
0 answers
50 views

Connecting to a Cisco Switch Using LDAP Authentication via FreeRADIUS

I have a problem with my FreeRADIUS server. I would like to connect to my Cisco switches using LDAP authentication from my FreeRADIUS server, but only for people who are part of a specific group. I ...
Enzo's user avatar
  • 3
-1 votes
1 answer
120 views

The implementation of a switch-statement in ARM assembly seems too minimal

I was learning about how switch-statements work under the hood in C, so I decided to look at the compiled code. From what I understand, C uses a jump table to implement switch-statements. However, I ...
AsianDora's user avatar
0 votes
1 answer
63 views

Immediate break after input using switch or if

I am learning C right now and im at the very beginning. Here's my code: #include <stdio.h> int main (){ char operator; double num1; double num2; double result; printf("\n Enter an ...
Bunyamin Erkaya's user avatar
1 vote
2 answers
57 views

How can i make my code rerun after Ending?

switch(choice) { case 1: double sum = 0; for (int i = 1; i <= 5; i++) { System.out.println("Enter " + i + "th number: ...
Prime Yt's user avatar
0 votes
1 answer
34 views

Crystal Report If formula with multiple conditions

I'm getting an error message with this formula but can't see the wood for the trees of what's missing - please help! if {vehinv_rec.master_class_2} = "RCV" and if {vehinv_rec.chassis_model} ...
Lizzi McCarthy's user avatar
1 vote
2 answers
63 views

How to skip vars_prompt if variables exist within import_playbook?

I have this playbook script to execute some basic task on the switch and firewall. Requirement : Case 1. User need to execute the parent script to perform all basic task on child 1 and child 2. Case ...
Febry Citra Prawira Negara's user avatar
-1 votes
2 answers
86 views

What should I do if ifstream does not work in the switch case?

In the code snippet below, I'm calling 2 different files. The first time everything works and the text is extracted from the file correctly, but when the second file is called from within the switch ...
Дина's user avatar
0 votes
0 answers
47 views

Why is the switch not returning the information from a different method?

I am trying to change my coding so that the switch function can be placed in a different method but be used by the first method. Here is the code for context: static void Main(string[] args) { ...
user25026495's user avatar
0 votes
1 answer
17 views

Crystal reports highlighting

I have a field in a Crystal Report that I want to highlight based on multiple Criteria. I cannot figure out a way to get a switch and/or if statement to work for me. This is for a productivity report. ...
Darrell's user avatar
  • 49
0 votes
1 answer
18 views

Adding dates to a DAX sumx/switch/filter query

I have inherited an existing DAX statement in a power BI report which calculates fees based on sources and products; Fee= SUMX( FILTER( 'Accounts', AND( RELATED('...
Aimee's user avatar
  • 1
2 votes
5 answers
175 views

Skipping a case statement in a switch [closed]

I have a switch statement that I specially need the cases to fall through. But have also a condition which is a bit of an edge case where I need to skip a case. I've made it a simple visualization ...
The Welder's user avatar
  • 1,014
1 vote
1 answer
53 views

Type guarding class in switch statement

I haven't use Typescript in many years and can't remember nor find how to type guard many classes inside a switch statement correctly. class A {} class B {} class C {} type OneOfThem = A | B | C; ...
Ettapp's user avatar
  • 878
-2 votes
1 answer
59 views

Choosing Named Range via formula

So I have this formula: At a high level, the formula goes like this: If [Dynamic Array #1] = False, 0, Index( If [Dynamic Array #2] = 1, Named Range A, Named Range B <-- Problem ...
Kaz's user avatar
  • 1,332

15 30 50 per page
1
2 3 4 5
394