F# 中的 nested if 语句函数

首页 / F#入门教程 / F# 中的 nested if 语句函数

在F#编程中,嵌套 if/thenif/then/else语句始终是合法的,这意味着您可以在另一个ifelse if语句中使用一个ifelse if语句。

nested if - 语法

if expr then
   expr
   if expr then
      expr
   else
      expr
else
   expr

nested if - 示例

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

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

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/fsharp/fsharp-nested-if-statements.html

来源:LearnFk无涯教程网

Value of a is 100 and b is 200

Exact value of a is: 100
Exact value of b is: 200

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

左耳听风 -〔陈皓〕

玩转Spring全家桶 -〔丁雪丰〕

透视HTTP协议 -〔罗剑锋(Chrono)〕

SQL必知必会 -〔陈旸〕

Flutter核心技术与实战 -〔陈航〕

手机摄影 -〔@随你们去〕

说透芯片 -〔邵巍〕

快手 · 音视频技术入门课 -〔刘歧〕

大型Android系统重构实战 -〔黄俊彬〕

好记忆不如烂笔头。留下您的足迹吧 :)