Dart 编程 - If 语句



if…else 语句会在执行代码块之前评估条件。

以下是语法。

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

如果布尔表达式评估为 true,则 if 语句内的代码块将被执行。如果布尔表达式评估为 false,则 if 语句结尾处(在结束花括号后)的第一个代码块将被执行。

以下插图展示了 if 语句的流程图。

If Statement

示例

以下示例展示了如何在 Dart 中使用 if 语句。

void main() { 
   var  num=5; 
   if (num>0) { 
      print("number is positive"); 
   }    
}

上面的示例将打印 “number is positive”,因为 if 块中指定的条件为 true。

number is positive 
dart_programming_decision_making.htm
广告
© . All rights reserved.