Objective-C 中的 continue 语句
Objective-C 编程语言中的continue 语句有点像break 语句。 然而,continue 不是强制终止,而是强制循环的下一次迭代发生,跳过其间的任何代码。
对于 for 循环,continue 语句会导致执行循环的条件测试和递增部分。 对于 while 和 do...while 循环,continue 语句使程序控制传递给条件测试。
语法
在 Objective-C 中 continue 语句的语法如下 −
continue;
流程图
示例
#import <Foundation/Foundation.h>
int main () {
/* local variable definition */
int a = 10;
/* do loop execution */
do {
if( a == 15) {
/* skip the iteration */
a = a + 1;
continue;
}
NSLog(@"value of a: %d\n", a);
a++;
} while( a < 20 );
return 0;
}
当上面的代码被编译和执行时,会产生如下结果 −
2013-09-07 22:20:35.647 demo[29998] value of a: 10 2013-09-07 22:20:35.647 demo[29998] value of a: 11 2013-09-07 22:20:35.647 demo[29998] value of a: 12 2013-09-07 22:20:35.647 demo[29998] value of a: 13 2013-09-07 22:20:35.647 demo[29998] value of a: 14 2013-09-07 22:20:35.647 demo[29998] value of a: 16 2013-09-07 22:20:35.647 demo[29998] value of a: 17 2013-09-07 22:20:35.647 demo[29998] value of a: 18 2013-09-07 22:20:35.647 demo[29998] value of a: 19

objective_c_loops.html