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,808
questions
2
votes
1
answer
193
views
Why Must Variables used in Guarded Pattern Case Labels be Final/Effectively Final? (Java 21)
With the new Java 21 features, we have better Pattern Matching. With these features, we have guarded pattern case labels, where one can define a pattern guard for case labels that looks like the ...
6
votes
2
answers
586
views
How do I use the spaceship operator in a switch statement
The new <=> operator makes writing code more convenient and it can save some performance if the comparison algorithm is non-trivial, because it doesn't need to be repeated two times to get the ...
0
votes
1
answer
209
views
React.js switch case always returns default case
I am trying to use <select> tags to update information between components with the help of useContext(). The problem that I am facing is that the default case is always returned despite the ...
0
votes
1
answer
265
views
Seeking Cython Optimization for Conditional Branching: Is There an Equivalent to switch?
I am currently working on a Python project that I need to rewrite in Cython to enhance performance. In this Python code, there is a segment that uses a series of if/elif statements to determine the ...
0
votes
0
answers
95
views
Using String values in switch and StringLists in case
I have two different String lists: firstList [a, b, c] and secondList [d, e, f]. Is there a way I can use a list in a case statement?
To be clear, the intended behavior is something like this:
switch(&...
0
votes
2
answers
116
views
C++ Avoiding Duplicate Code in Switch Statements?
I am working on cleaning up an old platformer game of mine that was written outright horribly (sorry, past me). The execution time and memory management has not been great and so I'm trying to ...
-1
votes
1
answer
87
views
Why won't my input be displayed from an array of structure?
I am trying to make a program where I can add players' info. I can run the program, but when selecting 'view players record' the nicknames are ommited. Can anyone see the problem here?
#include <...
0
votes
1
answer
284
views
Add Row Context to DAX SWITCH Measure Power BI
The original aim was to create 31 columns, that assess the DAY part of 3 dates and result a specific string in the particular column based on the IF statement. These 31 columns would then sit in a ...
1
vote
0
answers
24
views
Typescipt string literals as generics with dependent type: Exhausiveness check in switch
As a follow up of this question
I have the following code snippet:
const operations = {
DDB: ["getItem"] as const;
S3: ["putObject"] as const;
}
type service = keyof typeof ...
0
votes
1
answer
66
views
Typescipt string literals as generics: Exhausiveness check in switch
I have the following oversimplified code snippet:
type a = 'a' | 'b';
const fn = <T extends a>(param: T): T => {
switch(param) {
case 'a':
return 'a' as T;
case 'b':
...
0
votes
0
answers
38
views
DAX Advanced question with Time Intelligence and logic
this is my first post.
I am stuck with an advanced DAX problem. So far, I could not find anything in forums or anywhere that has worked. Even seasoned professionals have only provided ideas that have ...
1
vote
6
answers
73
views
Javascript Switch case statement : fall-through all cases when expression is 'all'
How can I implement this behavior in JavaScript Switch Statements
expression = 'all' or '1' or '2'
switch (expression)
{
case "all" : print case 1 and case 2
case "1&...
0
votes
0
answers
79
views
How to style mui switch track thumb and change it's position?
i'm trying to style my switch from material UI to look like this
enter image description here
and right now it looks like this:
enter image description here
as I see from inspect I need to change this ...
0
votes
1
answer
45
views
How to remove pattern matching for verifying user information in scala?
I am new to Scala as have been java developer until now.
I have a functionality to login like where user can have multiple passwords:
def login(User user) : Boolean = {
String username = user....
0
votes
2
answers
191
views
How to set an error message when a field is empty?
I am doing an exercise in Java. How can I add an error message if the field Country is blank?
This is part of my code:
public class Nationality {
public static void main(String[] args) {
...