F# – if/elif/else statement

  • Post author:
  • Post category:F#
  • Post comments:2 Comments
F# - if/elif/else statement

F# – if/elif/else statement construct has multiple else branches.

Syntax F# if/elif/else statement

The syntax of an if/then/elif/else statement in F# programming language is −

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

Example

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

When you compile and execute the program, it yields the following output −

None of the values are matching

Value of a is: 100

Next Topic – Click Here

This Post Has 2 Comments

Leave a Reply