Top "Switch-statement" questions

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.

Java switch statement multiple cases

Just trying to figure out how to use many multiple cases for a Java switch statement. Here's an example of …

java syntax switch-statement
Why can't variables be declared in a switch statement?

I've always wondered this - why can't you declare variables after a case label in a switch statement? In C++ …

c++ switch-statement
How to use a switch case 'or' in PHP

Is there a way of using an 'OR' operator or equivalent in a PHP switch? For example, something like this: …

php switch-statement case
Switch statement for string matching in JavaScript

How do I write a swtich for the following conditional? If the url contains "foo", then settings.base_url is "…

javascript regex switch-statement
Java using enum with switch statement

I've looked at various Q&As on SO similar to this question but haven't found a solution. What I …

java enums switch-statement
Switch statement for greater-than/less-than

so I want to use a switch statement like this: switch (scrollLeft) { case (<1000): //do stuff break; case (>1000 &&…

javascript jquery comparison switch-statement
Is it possible to use the instanceof operator in a switch statement?

I have a question of using switch case for instanceof object: For example: my problem can be reproduced in Java: …

java switch-statement instanceof
Control cannot fall through from one case label

I am trying to write a switch statement that would type the search term in the search field depending on …

c# switch-statement
Should switch statements always contain a default clause?

In one of my first code reviews (a while back), I was told that it's good practice to include a …

default switch-statement
How can I compare strings in C using a `switch` statement?

In C there is a switch construct which enables one to execute different conditional branches of code based on an …

c string switch-statement string-comparison