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
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 ...
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
0 votes
2 answers
55 views

How to reuse switch block labels without goto?

How to implement the following code without goto and unnecessary code complexity? namespace Test { static class Program { bool keyA = false; bool keyB = false; // ... ...
ng256's user avatar
  • 94
0 votes
2 answers
88 views

bash case glob in order to match part of hostname and ignore last characters

we tested the following script - script.sh on machine hostname - presto-data1-01 , but seems the regex presto-data+([[:digit:]]) isn't good enough machines hosts are as example: presto-data1-01 presto-...
jessica's user avatar
  • 2,550
0 votes
1 answer
36 views

How can I populate a column with same values which is there in that column

I have the following table: The flat_id column will only contain 2 distinct values i.e. 'ABC123' and 'NA'. I need to create a new column new_flat_id which will contain the 'ABC123' values in all rows ...
Sk2415's user avatar
  • 51
1 vote
3 answers
57 views

doing operations for else-if "groups"

I had a pattern like this and didn't know a good way to handle it let i = Math.floor(5 * Math.random()) if (i == 0) { console.log('a') console.log('+') } else if (i == 1) { console....
Vagif VALIYEV's user avatar
0 votes
0 answers
23 views

Why can't I ping the remote pox controller on port 6633 or port 6533 from mininet?

Please help me troubleshoot my painpoint. I have mininet image running on a VM installed on Virtualbox that comes preinstalled with pox(ie the mininet vm image) and I have tried to run a simple ...
paul's user avatar
  • 1
-1 votes
1 answer
44 views

Serial port from Arduino to PC noise

I am trying to connect a on-off switch to an Arduino board, then connect the Arduino board to my PC through the serial port with the baud rate of 9600. The idea is that when the switch is off, a ...
Arma Yari's user avatar
0 votes
0 answers
79 views

Switch-statements: void_func(); break; vs return void_func();

I noticed that in the case of calling one void function inside a case inside a void function, the word break can be replaced with the return of the called function, if the common function contains ...
iEPCBM's user avatar
  • 231
1 vote
0 answers
61 views

Differences in Compilation Results Between GCC and Clang

I encountered a situation where my C code compiles successfully with GCC but generates errors when compiled with Clang. Here is my C code: #include <stdio.h> #include <stdlib.h> #include &...
Konvt's user avatar
  • 63
-3 votes
1 answer
83 views

Can you define a variable in ranges in java [closed]

When using variables can you define or specify that variable as all the numbers within a range like 1-10? I am using Switch statements and want to assign one of the case variables all the variables ...
Arnor's user avatar
  • 17
-3 votes
1 answer
52 views

Java Calculator Not Working - Need Help Troubleshooting ( Computer Science Beginner ) [closed]

I've written a simple calculator in Java that takes user input for two numbers and an operator. It's supposed to perform the corresponding mathematical operation and output the result. However, my ...
Sebastian Kramer Garfias's user avatar
0 votes
2 answers
42 views

Create almost similar classes based on conditions, without too much repetion of code

I have three cases say: Case1, Case2, Case3: I have to define three classes depending on which case is true. All the classes have almost the same methods except for some pre-processing depending on ...
junfan02's user avatar
  • 161
0 votes
1 answer
49 views

Calculation of income tax owed is not working correctly

this program will calculate your tax bracket by the entering your income and your marital status, s for single and m for married. The program will prompt you to enter income, then marital status. ...
user23760512's user avatar
0 votes
1 answer
15 views

this code cant really get it to work tried combining two separate codes into one but I am coming into trouble

need help with my code my switch statement doesn't work I've tried to change it from int to string but cant figure it out. The line I have trouble with is line 43 that one is the switch statement ...
Justin Villatoro's user avatar
-1 votes
2 answers
62 views

How do I have Access automatically display what type of device something is, based on what's input in another field on the same table?

I'm currently working on building a radio inventory database for a charity I work with. I have a table called "Radio Info" where I am putting in the info about the individual radios and ...
Brian Cook's user avatar
-1 votes
2 answers
75 views

How to execute multiple other cases inside of a case

So it is possible to fall-through the case to another case: switch(variable) { case 1: // do something 1 case 2: // do something 2 break; case 3: // do something 3 break; } ...
Haaldor's user avatar
  • 39
1 vote
1 answer
44 views

Switch executes default even with break in every case

So i'm trying to break out of the switch and while statements using the break in every case, yet even using the break statement my program keeps executing the default after the specific case code is ...
Heaper's user avatar
  • 15
0 votes
0 answers
35 views

How can I switch to pop up facebook sign up page in Selenium?

I am not able to switch to pop up facebook sign up page using selenium.Tried switch to method but still not working. FB Signup page Tried below code public void createNewAccount() { driver....
S Taheri's user avatar
0 votes
1 answer
87 views

Can you break out of a switch case from within a loop?

I have a list of objects that I don't want to contain duplicates. Since the objects are expensive to create, I don't want to use a set, as that requires an object to be created first, before ...
TigersEye120's user avatar
2 votes
2 answers
127 views

Runtime cast of void pointer

I'm writing a C program that applies a different type of quantization to an array depending on an environmental variable. The problem is that, I need to use the same function void foo(void* ptr, ...
Saverio Pasqualoni's user avatar
1 vote
1 answer
148 views

Using bash case statement in gitlab ci/cd to set variables

I'm trying to create a pipeline and set some variables from gitlab based of the git branch, in my case staging, master and everything else branch: --- stages: - deploy - pre - pro ....
Richzendy's user avatar

15 30 50 per page
1
2 3 4 5
237