D语言continue语句

continue语句在D编程语言的工作原理有点像break语句。而不是强迫终止,而是继续强制循环发生的下一次迭代,在两者之间跳过任何代码。

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

语法

D语言continue语句语法如下所示:

continue;

流程图:

例子:

import std.stdio;
 
int main ()
{
   /* local variable definition */
   int a = 10;

   /* do loop execution */
   do
   {
      if( a == 15)
      {
         /* skip the iteration */
         a = a + 1;
         continue;
      }
      writefln("value of a: %d", a);
      a++;
     
   }while( a < 20 );
 
   return 0;
}
当上面的代码被编译并执行,它会产生以下结果:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16
value of a: 17
value of a: 18
value of a: 19
联系我们

邮箱 626512443@qq.com
电话 18611320371(微信)
QQ群 235681453

Copyright © 2015-2022

备案号:京ICP备15003423号-3