如何在目标c中使用goto语句?

Jas*_*shu 4 goto objective-c

我想通过检查相同方法中的条件来跳过一些代码行。我使用了 goto 语句,但它显示“无法从此 goto 语句跳转到标签”。有没有其他方法可以跳过代码?我做的是..

if(condition)
       goto skipped;
 //code to skip
 //code to skip

skipped:
 //code to execute
Run Code Online (Sandbox Code Playgroud)

Mar*_*ars 6

goto 肯定有合法用途,所以我认为这值得一个正确的答案:
您可能失败的一些可能原因:

  • 范围问题(尝试跳转到新功能等)
  • 跳过声明/析构函数

阅读更多:http : //en.cppreference.com/w/cpp/language/goto