switch-statement Questions

16

Solved

Just trying to figure out how to use many multiple cases for a Java switch statement. Here's an example of what I'm trying to do: switch (variable) { case 5..100: doSomething(); break; } vers...
Croze asked 23/2, 2011 at 2:17

2

Solved

Why do I get a "not all code paths return a value", for VeryBoolToBool() in the following code? public enum VeryBool { VeryTrue, VeryFalse }; public bool VeryBoolToBool(VeryBool veryBool) { swit...
Fox asked 24/12, 2013 at 10:17

13

Solved

I have the following enum: enum EditMode { View = 0, Edit = 1, Delete = 2 } Let's assume I have a variable of the enum type var editMode = EditMode.Edit; Why does the following code not work (...
Resolve asked 2/1, 2015 at 19:22

13

Solved

This should be pretty simple but even after checking all documentation and on-line examples I don't get it. I'd like to use switch() to replace the values of a character vector. A fake, extremely...
Lycian asked 1/7, 2015 at 9:1

8

Solved

First I'll state that I'm much more familiar with enums in C# and it seems like enums in java is a quite mess. As you can see, I'm trying to use a switch statement @ enums in my next example but I...
Netty asked 15/4, 2012 at 10:59

14

Solved

I tried searching around, but I couldn't find anything that would help me out. I'm trying to do this in SQL: declare @locationType varchar(50); declare @locationID int; SELECT column1, column2 F...
Incommodity asked 15/10, 2008 at 21:4

1

Solved

I'm developing with Java 17 in IntelliJ IDEA 2022.2. In some cases 'switch' expression does not cover all possible input values is shown, but in some not. I'd like to figure out why. Let's assume t...
Brieta asked 9/2, 2023 at 9:5

4

Solved

JSLint is complaining that (true) is a weird condition. Which is understandable if I wasn't using it on a reversed switch statement. So is JSLint wrong or should I not be using reversed switch stat...
Orten asked 5/10, 2011 at 8:31

3

Solved

It is possible to replace block of if( .. instanceof ...), elseif(... instanceof ...), ... with switch? For example: <?php $class = ..... //some class if($class instanceof SomeClass) { //do ...
Louettalough asked 4/5, 2016 at 13:27

6

Solved

My intention is to call two cases inside another case in the same switch statement, switch (orderType) { case 1: statement 1; break; case 2: statement 2; break; case 3: **call case 1;** ...
Cordes asked 19/7, 2015 at 6:23

26

Solved

I need multiple cases in switch statement in JavaScript, Something like: switch (varName) { case "afshin", "saeed", "larry": alert('Hey'); break; default: alert(...
Aenneea asked 3/11, 2012 at 9:43

4

Solved

As part of Java SE 12, switch expressions were introduced and since Java SE 14, they have been standardized. How are they different from switch statements?
Pomade asked 10/1, 2021 at 18:50

7

Please explain why Python does not have the switch-case feature implemented in it.
Pastel asked 12/10, 2017 at 3:44

5

Solved

I have been wondering for a while if I can use a variable in JS before it is defined, such as the following: var country = "USA"; switch (country) { case "USA": country = i; case "blach": //no...
Steep asked 26/11, 2013 at 15:12

10

Solved

How do I write a switch for the following conditional? If the url contains "foo", then settings.base_url is "bar". The following is achieving the effect required but I've a feel...
Sofar asked 24/5, 2010 at 11:33

2

Solved

How to use Swift literal regex expressions in switch case pattern statements? Based on the examples from WWDC 2022 presention slides, the following is expected to compile and run OK: import Foundat...
Highstepper asked 11/1, 2023 at 6:14

12

Solved

If I have a switch-case statement where the object in the switch is a string, is it possible to do an IgnoreCase compare? I have for instance: string s = "house"; switch (s) { case &quot...
Snowonthemountain asked 25/2, 2010 at 13:7

10

Solved

I basically want to do this: switch($someString.ToLower()) { "y", "yes" { "You entered Yes." } default { "You entered No." } }
Winger asked 16/8, 2010 at 13:47

1

Solved

In rust you can do things like this: for n in 1..101 { let triple = (n % 5, n % 2, n % 7); match triple { // Destructure the second and third elements (0, y, z) => println!("First is `0...
Pierre asked 26/12, 2022 at 19:42

6

Why doesn't the switch expression allow long, float, double or boolean values in Java? why is only int (and those that are automatoically promoted to int) allowed?
Denisdenise asked 28/2, 2011 at 12:15

5

Solved

I'm using java 1.7 in intellij and it's giving me a compile error as if I'm using pre-1.7. Saying, "Incompatible type. Found 'java.lang.String'. required 'byte, char, short, or int'. I'm rattling ...
Insphere asked 10/9, 2014 at 15:6

6

Solved

I implemented a font system that finds out which letter to use via char switch statements. There are only capital letters in my font image. I need to make it so that, for example, 'a' and 'A' both ...
Sine asked 27/3, 2012 at 3:44

9

Solved

How to implement equivalent of following Java switch statement code in Kotlin? switch (5) { case 1: // Do code break; case 2: // Do code break; case 3: // Do code break; }
Tripinnate asked 4/11, 2018 at 5:58

4

Solved

I was expecting the Python match/case to have equal time access to each case, but seems like I was wrong. Any good explanation why? Lets use the following example: def match_case(decimal): match d...
Cornelia asked 21/7, 2021 at 21:19

3

I'm looking for a way to catch multiple types of errors in a catch. I've tried fallthrough and the comma separated style from a switch statement and neither works. The docs say nothing about catchi...
Alan asked 19/4, 2016 at 21:35

© 2022 - 2024 — McMap. All rights reserved.