F# - if/elif/else 語句



if/then/elif/else 結構有多個 else 分支。

語法

F# 程式語言中 if/then/elif/else 語句的語法為:-

if expr then
   expr
elif expr then
   expr
elif expr then
   expr
...
else
   expr

示例

let a : int32 = 100

(* check the boolean condition using if statement *)

if (a = 10) then
   printfn "Value of a is 10\n"
elif (a = 20) then
   printfn " Value of a is 20\n"
elif (a = 30) then
   printfn " Value of a is 30\n"
else
   printfn " None of the values are matching\n"
   printfn "Value of a is: %d" a

編譯並執行程式後,將生成以下輸出:-

None of the values are matching

Value of a is: 100
fsharp_decision_making.htm
廣告
© . All rights reserved.