iOS return、break和continue的区别
作者:
邓布利多教授 | 来源:发表于
2020-03-07 11:50 被阅读0次- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = UIColor.whiteColor;
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
btn.center = self.view.center;
btn.backgroundColor = UIColor.redColor;
[btn addTarget:self action:@selector(buttonSelectAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
-(void)buttonSelectAction{
NSLog(@"开始");
[self testMethod];
NSLog(@"结束");
}
-(void)testMethod{
NSLog(@"方法内部开始");
for (int i = 0; i < 10; i ++) {
if (i == 5) {
NSLog(@"进入!");
// return;/// 跳出当前作用域,返回到函数调用处,继续执行
// break;/// 跳出当前代码块,继续执行
// continue;/// 继续执行
}
NSLog(@"执行中...");
}
NSLog(@"方法内部结束");
}
本文标题:iOS return、break和continue的区别
本文链接:https://www.haomeiwen.com/subject/vymqdhtx.html
网友评论