Questions tagged as 'switch'

2
answers

What is a loose comparison?

In documentation of PHP, about switch says:    Note : Note that switch / case does loose comparison . What is a loose comparison? And what's the difference between a loose and a rigid comparison?     
asked by 26.06.2017 / 19:15
2
answers

What's the difference between Switch, Case and If, Else?

I would like to know the difference between switch .. case and if .. else . What offers better "performance"?     
asked by 13.04.2015 / 20:33
3
answers

Is it wrong to use multiple cases for the same action on the switch?

Is it wrong to do this with switch ? I programmed it like that, is it wrong? switch(estado){ case "AL": case "BA": case "CE": case "MA": case "PB": case "PE": case "PI": case "RN": case "SE": //FAZ ALGO AQUI PARA TODOS OS CASES DO NORDES...
asked by 25.09.2017 / 21:22
1
answer

Why is using String in a switch block more efficient than in an if-else block?

According to Java documentation : / p>    The Java compiler generally generates more efficient bytecode from switch statements that use String objects than from chained if-then-else statements.     
asked by 26.08.2015 / 16:37
1
answer

Why can not you declare a variable within a case?

Why does not this compile? #include <stdio.h> int main(void) { int valor = 0; scanf("%d", &valor); switch (valor) { case 0: int variavel = 1; printf("%d", variavel); break; default:...
asked by 09.01.2017 / 16:02
3
answers

What is the difference between return and break in a switch case?

In some situations you need to practice switch case for optimization and improvement of code. I have an application developed for Android using Java, which in the case is used in both situations. Below I have an example using return...
asked by 05.01.2017 / 17:56
1
answer

How does the switch work under the rags?

Viewing these comments about using switch is in doubt as to how it works even and why it is different from if when only buying by equality of a single variable against a sequence of values. p> How is this compiled? Should it...
asked by 11.01.2017 / 12:20
1
answer

Javascript performance: switch or if nested?

Which of the two alternatives provides the best performance in Javascript: switch or if nested? if { ... } else { if { ... } else { if { ... } else { ... } } } or switch(expression) { case n:...
asked by 20.06.2014 / 18:14
3
answers

Use OR operator in a CASE in PHP

How to use the or operator in a control structure switch ? Example switch ($options) { case 1 || case 2: echo "Valor de opção 1 e 2"; break; case 3: echo "Valor de opção 3"; break; }  ...
asked by 10.04.2015 / 21:58
2
answers

I know the value of the variable, but the switch only goes to the default

After a search, I get the following result: // O resultado desta linha é I ou II ou III; echo $subsecao; // O resultado desta linha é string; echo gettype($subsecao); // Faço um switch p...
asked by 22.04.2015 / 14:55