How can I use goto in a switch statement in Objective-C?

goto, iphone, objective-c, switch-statement

Solution

It's generally very bad practice to unconditionally jump like you're asking.

I think a more readable/maintainable solution would be to place the shared code in a method and have multiple cases call the method.

If you really want to, you can use `goto` to do something like:

switch(viewNumber) {
    case 500:
        // [...]
        goto jumpLabel;
    case 501:
        // [...]
        break;
    case 502:
        // [...]
        jumpLabel:
        // Code that 500 also will execute
        break;
    default:break;
}

Note: I only provided the code example above to answer your question. I now feel so dirty I might have to buy some Bad Code Offsets.

Problem

In my code I need to be able to jump (goto) a different case within the same switch statement. Is there a way to do this? My code is something like this: (There is a lot of code I just left it all out) ``` switch (viewNumber) { case 500: // [...] break; case 501: // [...] break; . . . . . case 510: // [...] break; default: break; ``` } Thank you for your time! -Jeff

Original source