'OCaml loops: imperative vs recursion [closed]

I just stumbled upon some OCaml code that writes a loop like this:

    let r = ref (f 0) in
    for i = 1 to k - 1 do
      r := f i * !r
    done ;
    !r
  in

Which is interesting as I normally see this done using recursive functions in OCaml usually. Is there an advantage to one versus the other?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source