(* Imperative style *) let count_imp lsides rsides = let total = ref 0 in for ls = 0 to lsides - 1 do for rs = 0 to rsides - 1 do for le = ls to lsides - 1 do for re = rs to rsides - 1 do if ls = 0 || rs = 0 then incr total done done done done; !total;; count_imp 3 3;;