What is the programming pattern with multiple if else branching

If you are looking for how to do arbitrary early returns you can use:

let f x y z =
  let exception Return of int in
  try
    if x = 1 then raise (Return 0);
    if y = 2 then raise (Return 1);
    z
  with Return x -> x

Anecdotally, exceptions are fast in OCaml.

2 Likes