return、break 和continue 的使用区别
2020-05-22 本文已影响0人
稀释1
-(void)viewDidLoad{
[super viewDidLoad];
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 < 5; i ++) {
for (int j = 0; j<4; j++) {
if (j == 0) {
NSLog(@"进入! j==%d",j);
// return;// 跳出当前作用域,返回到函数调用处,继续执行
break;// 结束当前循环 跳出当前代码块,继续执行
// continue;// continue之后的代码不会执行 进行下一轮循环
}
NSLog(@"执行中...j==%d",j);
}
NSLog(@"执行中...i==%d",i);
}
NSLog(@"方法内部结束");
}