'else case' condition in 'switch'
See original GitHub issueI think it would be useful to be able to write the following:
switch (thing)
case (is SomeThing) {
}
else if (is OtherThing) {
}
else {
}
To be able to handle the case that SomeThing
and OtherThing
aren’t disjoint.
Currently the only way to write this is:
switch (thing)
case (is SomeThing) {
}
else if (is OtherThing thing) {
}
else {
}
WDYT?
Issue Analytics
- State:
- Created 7 years ago
- Comments:13 (12 by maintainers)
Top Results From Across the Web
javascript - Switch case - else condition - Stack Overflow
The switch statement will execute the first matching case, and then keep going (ignoring all further case labels) until it gets to either...
Read more >switch - JavaScript - MDN Web Docs - Mozilla
The switch statement evaluates an expression, matching the expression's value against a series of case clauses, and executes statements ...
Read more >The switch Statement (The Java™ Tutorials > Learning the ...
An if-then-else statement can test expressions based on ranges of values or conditions, whereas a switch statement tests expressions based only on a...
Read more >Conditional Statements: If, Else, and Switch - KIRUPA
As we can see, if / else statements are very similar to switch statements and vice versa. The default case block becomes an...
Read more >if-else vs switch - Javatpoint
Based on the result of the expression in the 'if-else' statement, the block of statements will be executed. If the condition is true,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I assume it would be a syntax error: after the first
else
, only otherelse
s are allowed, just like in anif
(if you add anotherif
that’s not anelse if
, that’s a separate control structure).Must say that my first reaction is to agree with @Zambonifofex here. Not sure if it’s worth adding a strange new syntax just for this.