switch-statement Questions

29

Solved

I have a question of using switch case for instanceof object: For example: my problem can be reproduced in Java: if(this instanceof A) doA(); else if(this instanceof B) doB(); else if(this inst...
Shawannashawl asked 7/4, 2011 at 10:3

2

Solved

Hopefully by the title of this, it's clear I'm not asking does Swift support the Switch statement. I'm specifically asking if Swift supports Switch expressions, akin to what C# has. The difference ...
Adachi asked 2/8, 2022 at 21:34

10

Solved

My switch-case statement works perfectly fine yesterday. But when I run the code earlier this morning eclipse gave me an error underlining the case statements in color red and says: case expression...
Worldbeater asked 1/2, 2012 at 8:15

6

How do I do a conditional dispatch on a string in Common Lisp? I'm looking for something like: (case str ("a" "found an a") ("abc" "found an abc") (otherwise "other")) so (case "a") returns "...
Disbelieve asked 16/9, 2015 at 5:58

2

Solved

I'd like to use a "switch/case" structure to decide which variable to assign a value to based on some parameter: a, b = [init_val] * 2 # This doesn't exist in Python. switch param case '...
Wertheimer asked 29/3, 2018 at 0:19

7

Solved

I'm trying to write an R script to evaluate different expressions based on fitting a value within ranges. The idea is that if Length is within one range, it will get evaluated one way, and if it's ...
Serg asked 11/9, 2012 at 23:4

4

Solved

I am trying to understand how the switch is working in the dart. I have very simple code: methodname(num radians) { switch (radians) { case 0: // do something break; case PI: // do something ...
Polytypic asked 15/6, 2014 at 11:47

32

Solved

Seeing as C# can't switch on a Type (which I gather wasn't added as a special case because is relationships mean that more than one distinct case might apply), is there a better way to simulate swi...
Wamble asked 18/11, 2008 at 15:4

3

Solved

I have an enum type that extends String in Swift. When I try to use a switch I got an error: Case label in a switch should have at least one executable statement Here is my code: enum UserIn...
Aorist asked 25/11, 2014 at 16:1

17

Solved

In my code, the program does something depending on the text entered by the user. My code looks like: switch (name) { case text1: { //blah break; } case text2: { //blah break; } case text...
Snooze asked 23/5, 2013 at 6:10

26

Solved

Is there a way to fall through multiple case statements without stating case value: repeatedly? I know this works: switch (value) { case 1: case 2: case 3: // Do some stuff break; case 4: ...
Obliquity asked 16/9, 2008 at 1:34

11

Why is my compiler telling me: Incompatible Types: Required: Boolean Found: Int under case 0 & case 1 For instance: public void test(boolean isOn){ switch (isOn){ case 0: if (isO...
Corespondent asked 13/10, 2013 at 22:50

6

Solved

Switch statements are typically faster than equivalent if-else-if statements (as e.g. descibed in this article) due to compiler optimizations. How does this optimization actually work? Does anyone...
Boat asked 14/1, 2009 at 23:13

2

Solved

Overview I would like to use switch statement by matching array type. I have the following classes. Class: class A {} class B : A {} Switch on single value works: let a : A = B() switch a {...
Otoplasty asked 21/3, 2018 at 12:45

1

Solved

I don't understand why the first snippet compiles fine : var res = getResult(s); public static double getResult(Shape s) { switch(s) { case Rectangle r : return 2* r.largeur() + 2* r.longueur();...
Longobard asked 23/5, 2023 at 10:30

9

Solved

Is it possible to have a switch in C# which checks if the value is null or empty not "" but String.Empty? I know i can do this: switch (text) { case null: case "": break; } Is there something...
Warner asked 11/1, 2009 at 1:56

18

Solved

How would you do this PHP switch statement? Also note that these are much smaller versions, the one I need to create will have a lot more values added to it. Version 1: switch ($p) { case 'home':...
Lemmy asked 21/8, 2009 at 1:52

4

Solved

OK, so let's say I have this: $(function() { $('#good_evening').keyup(function () { switch($(this).val()) { case 'Test': // DO STUFF HERE break; } }); }); ... this would only run if you t...
Percutaneous asked 11/9, 2010 at 7:29

15

Solved

Integer i = ... switch (i) { case null: doSomething0(); break; } In the code above I can't use null in the switch case statement. How can I do this differently? I can't use default because t...
Leaguer asked 26/4, 2012 at 11:4

23

Solved

Compiling the following code gives the error message: type illegal. int main() { // Compilation error - switch expression of type illegal switch(std::string("raj")) { case"sda&qu...
Bradbradan asked 16/3, 2009 at 12:14

12

Solved

I'm currently adding some new extended classes to this code: foreach (BaseType b in CollectionOfExtendedTypes) { if (b is ExtendedType1) { ((ExtendedType1) b).foo = this; } else if (b is Exte...
Gies asked 21/10, 2008 at 21:52

2

Solved

Why does this code fail: OKAY = 200 NOT_FOUND = 404 INTERNAL_SERVER_ERROR = 500 match status: case OKAY: print('It worked') case NOT_FOUND: print('Unknown') case INTERNAL_SERVER_ERROR: print...

8

Solved

Is there a way to use relational operators (<,<=,>,>=) in a switch statement? int score = 95; switch(score) { case (score >= 90): // do stuff } the above example (obviously) doesn't ...
Kondon asked 9/10, 2013 at 10:38

6

Solved

I am trying to do the following using case in Bash (in Linux). If X is between 460 and 660, output X information. If X is between 661 and 800, do something else. Etc. Right now this is what I h...
Stacystadholder asked 27/9, 2012 at 4:16

19

Solved

When I try to compile I get this error: 1>------ Build started: Project: snake, Configuration: Debug Win32 ------ 1> exercise.cpp 1>c:\users\robin\documents\visual studio 2010\projects\snake\snak...
Terhune asked 24/2, 2012 at 14:19

© 2022 - 2024 — McMap. All rights reserved.