Break a loop in OCaml
问题 I often need to break a loop in OCaml, there are at least two ways: (* by exception *) try for i = 0 to 100 do ... if cond then raise BreakLoop done; ... with BreakLoop -> ... (* by while *) let cond = ref false in let i = ref 0 in while (not !cond) && (i<= 100) do ... i := !i + 1 done; if !cond then ... What I care most is the optimisation of running time, as long as the program can be easily read and understood. The way while makes loops complicated when there are several nested loops. I