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.