当前位置: 首页 > 文档资料 > F# 中文教程 >

if /then statement

优质
小牛编辑
115浏览
2023-12-01

if/then语句由一个布尔表达式后跟一个或多个语句组成。

语法 (Syntax)

F#中的if/then结构具有以下语法 -

(* simple if *)
if expr then
   expr

流程图

如果那么声明

例子 (Example)

let a : int32 = 10
(* check the boolean condition using if statement *)
if (a < 20) then
   printfn "a is less than 20\n"
   printfn "Value of a is: %d" a

编译并执行程序时,它会产生以下输出 -

a is less than 20
Value of a is: 10