Purists will hate this, but I commonly use exceptions to emulate the “return” statement from the lesser languages.
This little fellow makes things look less nasty:
let label (type u) (f: (u -> _) -> u) : u =
let exception R of u in
try f (fun x -> raise (R x)) with R u -> u
let f () : int =
label begin fun return ->
if cond1 then
if cond2 then
3 (* result *)
Almost as good as in C, buahahahaha.
P.S. I wish OCaml had a built-in “return” construct, with a more efficient implementation, but I wouldn’t dare sending a PR on this (even though it’s probably trivial to implement). A “goto” statement would also be welcome (for modelling state machines and such, especially inside generated code), but I guess that it’s even more of a blasphemy.