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.

Why Switch/Case and not If/Else If?

This question in mainly pointed at C/C++, but I guess other languages are relevant as well. I can't understand …

c++ c switch-statement conditional-statements
Case in protected switch

Possible Duplicate: When converting a project to use ARC what does “switch case is in protected scope” mean? Got the …

objective-c switch-statement
How to get 'switch-case' statement functionality in Django templates?

I found a link to have a 'switch' tag in Django templates, but I was wondering if this can be …

django django-templates switch-statement case
How to use a PHP switch statement to check if a string contains a word (but can also contain others)?

I'm using a PHP switch to include certain files based on the incoming keywords passed in a parameter of the …

php string switch-statement url-parameters php-include
Swift: testing against optional value in switch case

In Swift, how can I write a case in a switch statement that tests the value being switched against the …

swift enums switch-statement optional
Switch on Enum (with Flags attribute) without declaring every possible combination?

how do i switch on an enum which have the flags attribute set (or more precisely is used for bit …

c# enums switch-statement flags bit
Jumping from one case to the default case in switch statement

switch(ch){ case 'a': //do something, condition does not match so go to default case //don't break in here, and …

c switch-statement break
In a switch case statement, it says "duplicate case value" comes up as an error. Anyone know why?

I am working on a rock paper scissors program, but this time the computer chooses rock half the time, scissors …

c++ switch-statement dev-c++
Why does C# have break if it's not optional?

When I create a switch statement in VS2008 C# like this (contrived): switch (state) { case '1': state = '2'; …

c# switch-statement break
Declaring variables inside a switch statement

I saw a few answers to this issue, and I get it — you can't declare and assign variables inside a …

objective-c c variables switch-statement declaration