F# – Nested if Statement

  • Post author:
  • Post category:F#
  • Post comments:1 Comment
F# - Nested if Statement

F# Nested if Statement it is always legal in F# programming to nest if/then or if/then/else statements, which means you can use one if or else if statement inside another if or else if statement(s).

Syntax of F# Nested if Statement

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

Example

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

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

Value of a is 100 and b is 200

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

Next Topic – Click Here

This Post Has One Comment

Leave a Reply