Questions tagged as 'switch'

2
answers

Alternative for Switch within Switch

I'm making a decision structure that depends on more than one variable, but readability and maintenance using if or switch are bad. What alternatives do I have for this case? Example of% nested% nested: switch (var1) {...
asked by 01.06.2016 / 00:58
2
answers

Switch case Kotlin

In Java I use switch in several situations, as in the example below : public class SwitchDemo { public static void main(String[] args) { int month = 8; String monthString; switch (month) { case...
asked by 18.08.2017 / 20:49
2
answers

Custom Search Tool Optimization

Now, I'm creating a search page that receives, via POST , information from a form containing several checkbox . See below that there are several sequences of results and one orange is marked as an example: WhenIclicksearch,theinfo...
asked by 27.02.2015 / 21:29
1
answer

Using Switch Case for Intervals

My teacher passed an exercise in which we should use the cases of a switch to handle intervals, he said strictly that we should use the switch and we can not use if nor while/do . I've tried the following code: switch(saldo)...
asked by 24.11.2017 / 18:17
2
answers

Switch case Java ends for no reason

I have an example of switch-case with 8 options. However from case 7 it ends the program. It was for him to go back to the menu option after running. Does case have options limit? Follow the code: import java.util.Scann...
asked by 12.08.2016 / 14:59
2
answers

How to receive a string and by the switch to check in C?

I have to develop an algorithm that gets the name of a place, for example "School", and based on this, make a check of the string in switch , and if it is "School ", then he sends a message to the user about what to do, for example," Stu...
asked by 28.03.2017 / 00:07
1
answer

Is it possible to use the "break" argument on a "switch" to break a loop?

When I want to break a loop of a for , while or foreach I always use break; within a if with the following structure: $teste = array(1,2,3,4,5); foreach($teste as $t){ if($t == 3){ echo "Terminando loop a...
asked by 20.04.2015 / 23:20
2
answers

How to make a switch in C #?

I see a lot of people saying it's wrong to switch in the code because it ends up weighing and it's ugly. Is it correct the way I'm using it and what would be an alternative to using it? Fill in the code for if / else ?...
asked by 29.11.2018 / 12:06
2
answers

What is the correct way to return a switch value?

How is the correct way to return the value of switch ? HTML: <h3 id="txtOcorrenciaStatus">Status</h3> Javascript: switch(ocoStatus) { case C: $("#OcorrenciaStatus").html("Concluído"); break; case A:...
asked by 27.12.2015 / 21:30
1
answer

Does the last statement on a switch need to 'break'?

I was watching some tutorials on YouTube and noticed that some programmers leave the last statement in a block switch without the word break . For example: switch(frutas){ case "abacaxi": abacaxi++; break; case "morango": mo...
asked by 02.01.2015 / 01:42