示例
以下程序使用嵌套的for循环来查找2到100之间的质数-
#import <Foundation/Foundation.h>
int main () {
/* local variable definition */
int a = 10;
/* while loop execution */
while( a < 20 ) {
NSLog(@"value of a: %d\n", a);
a++;
if( a > 15) {
/* 使用break语句终止循环 */
break;
}
}
return 0;
}
编译并执行上述代码后,将产生以下结果-
2020-08-05 22:15:46.905 test[12282] value of a: 10
2020-08-05 22:15:46.906 test[12282] value of a: 11
2020-08-05 22:15:46.906 test[12282] value of a: 12
2020-08-05 22:15:46.906 test[12282] value of a: 13
2020-08-05 22:15:46.906 test[12282] value of a: 14
2020-08-05 22:15:46.906 test[12282] value of a: 15