Skip to content

Instantly share code, notes, and snippets.

@celsojr
Last active September 18, 2016 18:42
Show Gist options
  • Save celsojr/04a3e18341c48b1df70d2482208183a4 to your computer and use it in GitHub Desktop.
Save celsojr/04a3e18341c48b1df70d2482208183a4 to your computer and use it in GitHub Desktop.
// F# calculating the factorial in imperative approach programming.
let Fact n =
let mutable x = n
let mutable y = 1
while x > 0 do
y <- y * x
x <- (x - 1)
y
for i in 0 .. 10 do
printfn "%02d! = %d" i (Fact i)
(* the output
00! = 1
01! = 1
02! = 2
03! = 6
04! = 24
05! = 120
06! = 720
07! = 5040
08! = 40320
09! = 362880
10! = 3628800
*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment