无涯教程-F# - if/then/elif/else 语句函数

39 阅读1分钟

If/Then/Elif/Else构造有多个Else分支。

if/then/elif/else - 语法

F#编程语言中IF/THEN/ELIF/ELSE语句的语法是-

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

if/then/elif/else - 示例

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

参考链接

www.learnfk.com/fsharp/fsha…