codecamp

D编程 if statement

if语句由一个布尔表达式后跟一个或多个语句组成。

if - 语法

D编程语言中IF语句的语法是-

if(boolean_expression) {
   /* statement(s) will execute if the boolean expression is true */
}

如果布尔表达式的计算结果为true,则执行if语句中的代码块。如果布尔表达式的计算结果为false,则执行if语句结束后(右大括号后)的第一组代码。

d编程语言将任何非零和非NULL值假定为TRUE,如果它是零或NULL,则假定它为FALSE值。

if - 流程图

D if statement

if - 示例

import std.stdio;
 
int main () { 
   /* local variable definition */
   int a=10; 
  
   /* check the boolean condition using if statement */
   if( a < 20 ) { 
      /* if condition is true then print the following */
      writefln("a is less than 20" ); 
   } 
   writefln("value of a is : %d", a); 
  
   return 0;
}

编译并执行上述代码时,将生成以下结果-

a is less than 20;
value of a is : 10


D编程 条件判断
D编程 if...else statement
温馨提示
下载编程狮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; }