F# – if/else statement

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

F# if/else statement can be followed by an optional else statement, which executes when the Boolean expression is false.

Syntax of F# if/else statement

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

if expr then
   expr
else
   expr

Flow Diagram

F# - if/else statement

Example

let a : int32 = 100

(* check the boolean condition using if statement *)

if (a < 20) then
   printfn "a is less than 20\n"
else
   printfn "a is not less than 20\n"
   printfn "Value of a is: %d" a

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

a is not less than 20

Value of a is: 100

Next Topic – Click Here

This Post Has 2 Comments

Leave a Reply