作者drag (京都念慈庵,贾诩念费翔)
看板MacDev
标题Re: [问题] goto的使用?
时间Thu Jun 12 16:43:45 2014
※ 引述《henry4343 (henry)》之铭言:
: 请问各位
: 我有一个goto的label,但我想要使用goto的时候才执行,有办法吗
: - (void) function {
: if() {
: goto: gotoLabel;
: }
: gotoLabel: {
: NSLog(@"goto");
: }
: }
: 我想要执行goto:的时候才会进到gotoLabel里,
: 没执行的时候会直接跳过gotoLabel那段程式码
: 请问这有办法做到吗?
: 感谢
不太确定为什麽要这样做,这样可以吗?
- (void) function {
if() {
goto: gotoLabel;
}
return;
gotoLabel: {
NSLog(@"goto");
}
}
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 118.169.195.39
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/MacDev/M.1402562631.A.098.html
1F:→ henry4343:抱歉我没有写很清楚,goto下面还有其他的code 06/12 22:14
2F:→ henry4343:只是不想执行gotoLabel里面的code,但还是要往下跑 06/12 22:14
1.这样呢?
- (void) function {
if() {
goto: gotoLabel;
}
gobackLabel: {
...(剩下的事情)...
}
return;
gotoLabel: {
NSLog(@"goto");
goto: gobackLabel;
}
}
2.或这样?(邪恶一点的作法)
#define Sub_process() NSLog(@"goto1"); \
NSLog(@"goto2");\
NSLog(@"goto3");
- (void) function {
if() {
Sub_process();
}
}
※ 编辑: drag (118.169.195.39), 06/13/2014 15:47:35
※ 编辑: drag (118.169.195.39), 06/13/2014 15:54:20