It seems it's possible with C#, but I need that with C++ and preferably cross platform.
Basically, I have a switch that sorts stuff on single criteria, and falls back to default processing on everything else.
Say:
switch(color) { case GREEN: case RED: case BLUE: Paint(); break; case YELLOW: if(AlsoHasCriteriaX) Paint(); else goto default; break; default: Print("Ugly color, no paint.") break; }
A label is a valid C# identifier followed by colon. In this case, case and default statements of a Switch are labels thus they can be targets of a goto. However, the goto statement must be executed from within the switch. that is we cannot use the goto to jump into switch statement .
@The Smartest: A switch statement in itself can already have plenty of goto s, but they are named differently: Each break is a goto. @chiccodoro That's nothing, actually each case is a label and switch essentially is a goto . Each break is a goto , but also each continue is a goto too.
Yes, it does.
"The GOTO statement is generally considered to be a poor programming practice that leads to unwieldy programs. Its use should be avoided."
Ahmed's answer is good, but there's also:
switch(color) case YELLOW: if(AlsoHasCriteriaX) case GREEN: case RED: case BLUE: Paint(); else default: Print("Ugly color, no paint.");
people tend to forget how powerful switches are
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