codecamp

D编程 do...while loop

与for和while循环不同,for和while循环在循环的顶部测试循环条件,而D编程语言中的do ... while循环在循环的底部检查其条件。


do ... while循环与while循环类似,不同之处在于,do ... while循环可确保至少执行一次。

do...while - 语法

D编程语言中do.while循环语法为

do {
   statement(s);
} while( condition );

do...while - 流程图

do...while loop in D

do...while - 示例

import std.stdio;

int main () {
   /* local variable definition */
   int a=10;

   /* do loop execution */
   do{
      writefln("value of a: %d", a);
      a=a + 1;
   }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: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19


D编程 for loop
D编程 nested loops
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }