F# - if/else 语句



if/then 语句后面可以是可选的 else 语句,当布尔表达式为 false 时执行。

语法

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

if expr then
   expr
else
   expr

流程图

Else Statement

示例

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.htm
广告
© . All rights reserved.