if/then语句后面可以跟一个可选的else语句,该语句在布尔表达式为false时执行。
F#编程语言中if/then/else语句的语法是 -
if expr then
expr
else
expr
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