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.