F # - Instruction if imbriquée

Il est toujours légal dans la programmation F # d'imbriquer des instructions if / then ou if / then / else, ce qui signifie que vous pouvez en utiliser une if ou else if déclaration dans un autre if ou else if déclaration (s).

Syntaxe

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

Exemple

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

Lorsque vous compilez et exécutez le programme, il produit la sortie suivante -

Value of a is 100 and b is 200

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