question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'else case' condition in 'switch'

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:13 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
lucaswerkmeistercommented, Dec 6, 2016

I assume it would be a syntax error: after the first else, only other elses are allowed, just like in an if (if you add another if that’s not an else if, that’s a separate control structure).

1reaction
quintessecommented, Dec 6, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found