0
Help me with this Switch please(por favor)
7 Antworten
+ 1
You shouldn't use conditionals for switch cases, use if/else if/else chains instead. You outright can't use conditionals for switch in the sololearn playground, but even in environments where it's permitted, it's bad practice.
For educational value though, some environments will let you do this if you use switch(true), because switch X case Y checks if X==Y
+ 1
People, thank you very much for your attention. They motivate me to continue studying. So "switch" is usually not a good practice.
0
Well, there's definitely something to be said for that too lol, but the main issue here is that your cases need to be definite values, preferably constants (eg string literals instead of a named variable, or commonly the values from an enum)
0
CyberFox friend.. In this exemplo I can apply *switch *..
Then I don't understand why not can aplly *Switch * in the first exercise... You can or anyone can help me?
https://code.sololearn.com/c7LFxOHQpOED/?ref=app
0
Note the case statements: case 1, case 2. 1 and 2 are definitely constants lol. Switch cases need to be simple values likes this.
0
I understand, that means that the cases of the Switch cannot be more complicated than an int, double or spring value.
Correct?