F# - if/else 语句

if/then 语句后面可以跟一个可选的 else 语句,该语句在布尔表达式为 false 时执行。

语法

F# 编程语言中 if/then/else 语句的语法为 −

if expr then
   expr
else
   expr

流程图

Else 语句

示例

let a : int32 = 100

(* check the boolean condition using if statement *)

if (a < 20) then
   printfn "a is less than 20\n"
else
   printfn "a is not less than 20\n"
   printfn "Value of a is: %d" a

当您编译并执行该程序时,它会产生以下输出 −

a is not less than 20

Value of a is: 100

❮ fsharp_decision_making.html