第21节:Objective-C continue语句



continue语句在Objective-C编程语言的工作原理有点像break语句。不是强制终止,而是继续下一个迭代的循环发生,跳过任何代码。

for循环中,continue语句导致循环条件测试和增量部分来执行。对于while 和 do...while循环,continue语句使程序控制通过条件测试。

语法:

Objective-C中的continue语句的语法如下:

continue;

流程图:

Objective-C continue statement

例如:

#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
", 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

来源:https://www.yiibai.com/objective_c/objective_c_continue_statement.html


0