F# - 嵌套 if 语句
在 F# 编程中嵌套 if/then 或 if/then/else 语句始终是合法的,这意味着您可以在另一个 if 或 else if 语句中使用一个 if 或 else if 语句 if 或 else if 语句。
语法
if expr then
expr
if expr then
expr
else
expr
else
expr
示例
let a : int32 = 100
let b : int32 = 200
(* check the boolean condition using if statement *)
if (a = 100) then
(* if condition is true then check the following *)
if (b = 200) then
printfn "Value of a is 100 and b is 200\n"
printfn "Exact value of a is: %d" a
printfn "Exact value of b is: %d" b
当您编译并执行该程序时,它会产生以下输出 −
Value of a is 100 and b is 200 Exact value of a is: 100 Exact value of b is: 200

