发布于 2015-08-16 14:44:07 | 99 次阅读 | 评论: 0 | 来源: 网络整理

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

语法

if语句在D编程语言的语法是:


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

如果布尔表达式的值为true,那么代码的if语句内的模块将被执行。如果布尔表达式计算为false,那么第一组代码的if语句(右大括号后)结束后,将被执行。

D编程语言假定任何非零和非空值作为true,如果它是零或为null,则假定为false。

流程图:

例子:


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
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务