D編程 while loop

2021-09-01 11:09 更新

只要給定條件為真,D編程語言中的while循環(huán)語句就會(huì)重復(fù)執(zhí)行目標(biāo)語句。

while - 語法

D編程語言中while循環(huán)語法為-

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; 
}

編譯并執(zhí)行上述代碼時(shí),將生成以下結(jié)果-

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


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號