I am wondering if this is a bug or a documented behaviour?

f1 = Function[v, 
  Do[If[v[[i]] < 0, Return[v[[i]]]], {i, 1, Length[v]}]]

c1 = Compile[{{v, _Integer, 1}}, 
  Do[If[v[[i]] < 0, Return[v[[i]]]], {i, 1, Length[v]}]]

When applying them to a list containing no negative numbers, we get different results:

In[66]:= Through[{f1, c1}[{1, 2, 3}]]

Out[66]= {Null, 3}

This has caused a bug when I tried to compile a short function (actually a modified version of it).

Do alone doesn't show the problem:

c2 = Compile[{}, Do[i, {i, 5}]]

c2[] (* returns nothing, as expected *)
Edit
Report