switch ("B")
{
case "A":
break;
case "B":
continue;
case "C":
break;
default:
break;
}
simple correct code in C++, but when made in javascript in stable chrome it just throws an error "Illegal continue statement", looks like continue statement is just disallowed in switch in javascript... Heard about return but it just returns and doesnt continue... So is there a way to continue switch in js?
continue
has absolutely nothing to do with switch
es, not in Javascript and not in C++:
int main()
{
int x = 5, y = 0;
switch (x) {
case 1:
continue;
case 2:
break;
default:
y = 4;
}
}
error: continue statement not within a loop
If you wish to break out of the case, use break
; otherwise, allow the case to fall through:
switch ("B")
{
case "A":
break;
case "B":
case "C":
break;
default:
break;
}
If you're looking for a shortcut to jump to the next case then, no, you can't do this.
switch ("B")
{
case "A":
break;
case "B":
if (something) {
continue; // nope, sorry, can't do this; use an else
}
// lots of code
case "C":
break;
default:
break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With