F# mainly increases the use of Functional Programming. F# contains constructs that allow you to write code in a more perfect style as well. A statement does something, has no return value, and can not be passed into a function as an argument. Conditional statements are features of a programming language that perform various computations or actions depending on whether you specified a Boolean that evaluates true or false. F# supports all imperative ways of approaching problems. F# takes a different approach than most functional programming language in that the evaluation of a statement can be put in any order. In F# we have a very succinct way of doing it with the if, elif and else statements.
If-Then/elif/else Decision
If-Then statements are common in many programming language although the syntax is different a little bit from language to language. The F# syntax looks like below:
Syntax-
// Syntax of If/than/elif/else
(* simple if *)
if expr then
expr
(* binary if *)
if expr then
expr
else
expr
(* multiple else branches *)
if expr then
expr
elif expr then
expr
elif expr then
expr
...
else
expr
Or
if a then
b
else c
First a is evaluated then if and only if a evaluates to true than it executes b otherwise it evaluates c.
If you consider a, b, c as statements then you can say that executes statement1 if the expression result is logically true. The else clause of if statements is optional. If the expression result is logically False and an else statement exists then the statements associated with the else statement will execute. When multiple if statements exists and the else clause is present, the else is related with the nearest preceding if statement in the same block.
Example-

open System
let printMessage condition =
if 5<6 then
printfn "6"
else
printfn "5"
let main() =
printMessage true
printfn "******"
printMessage false
Console.ReadKey(true) |> ignore
main()
Output-







Join the conversation! Your thoughts help the community grow.