title: "Break" for loop in OCaml
body: <p>I need to test all possible combinations in a 5 element array in OCaml, if any combination meets a condition, I must stop for loops and return that array, but is not easy return something in a for...</p>
  
  <p>I have this code:</p>
  
  <pre><code>let myfunction t =
   let arraycolours = Array.make 5 W in
    try
     for i=0 to 3 do
      Array.set arraycolours 0 (inttocolour i);
      for j=0 to 3 do
       Array.set arraycolours 1 (inttocolour j);
       for k=0 to 3 do
        Array.set arraycolours 2 (inttocolour k);
        for l=0 to 3 do
         Array.set arraycolours 3 (inttocolour l);
         for m=0 to 3 do
          Array.set arraycolours 4 (inttocolour m);
          if test arraycolours = t then raise Exit
         done
        done
       done
      done
     done
    with Exit -&gt; arraycolours;;
  </code></pre>
  
  <p>But there says:
  Error: This expression has type colour array
         but an expression was expected of type unit</p>
  
  <p>How can I return the array that meets condition?</p>