无涯教程-D语言 - while 循环函数

45 阅读1分钟

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

while - 语法

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

while(condition) {
   statement(s);
}

while - 流程图

while loop in D

while - 示例

import std.stdio;

int main () { /* 局部变量定义 */ int a=10;

/* while循环执行 */ 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

参考链接

www.learnfk.com/d-programmi…