阅读(3538) (0)

D编程 while loop

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

只要给定条件为真,D编程语言中的while循环语句就会重复执行目标语句。

while - 语法

D编程语言中while循环语法为-

while(condition) {
   statement(s);
}

while - 流程图

while loop in D

while - 示例

import std.stdio;

int main () { 
   /* local variable definition */
   int a=10;  
   
   /* while loop execution */
   while( a < 20 ) {
      writefln("value of a: %d", a); 
      a++; 
   }
  
   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: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19