F # - instruction if / then

Une instruction if / then consiste en une expression booléenne suivie d'une ou plusieurs instructions.

Syntaxe

La construction if / then en F # a la syntaxe suivante -

(* simple if *)
if expr then
   expr

Représentation schématique

Exemple

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

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

a is less than 20

Value of a is: 10