阅读(1861) (14)

D编程 continue statement

2021-09-01 10:57:05 更新

D编程语言中的CONTINUE语句的工作方式有点像break语句,但是,Continue并不强制终止,而是强制进行循环的下一次迭代,跳过其间代码。

continue - 语法

D中CONTINUE语句语法如下所示:-

continue;

continue - 流程图

D continue statement

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