F# - if/then 语句



If/then 语句包含一个布尔表达式及其后一个或多个语句。

语法

F# 中的 if/then 构造具有以下语法 −

(* simple if *)
if expr then
   expr

流程图

If then Statement

示例

let a : int32 = 10

(* check the boolean condition using if statement *)
if (a < 20) then
   printfn "a is less than 20\n"
   printfn "Value of a is: %d" a

当你编译和执行程序时,它会产生以下输出 −

a is less than 20

Value of a is: 10
fsharp_decision_making.htm
广告
© . All rights reserved.