在Objective-C编程语言的break语句有以下两种用法:
如果正在使用嵌套循环(即,另一循环内循环),break语句将停止执行最深层的循环,并开始执行下一行代码块后。
Objective-C中的break语句的语法如下:
break;
#import <Foundation/Foundation.h> int main () { /* local variable definition */ int a = 10; /* while loop execution */ while( a < 20 ) { NSLog(@"value of a: %d ", a); a++; if( a > 15) { /* terminate the loop using break statement */ break; } } return 0; }
上面的代码编译和执行时,它会产生以下结果:
2013-09-07 22:15:46.905 demo[12282] value of a: 10 2013-09-07 22:15:46.906 demo[12282] value of a: 11 2013-09-07 22:15:46.906 demo[12282] value of a: 12 2013-09-07 22:15:46.906 demo[12282] value of a: 13 2013-09-07 22:15:46.906 demo[12282] value of a: 14 2013-09-07 22:15:46.906 demo[12282] value of a: 15
来源:https://www.yiibai.com/objective_c/objective_c_break_statement.html