If you gonna go this way (what is really kinda strange to me for real code), probably the best you can do is to apply the same function (that does the same as the body of the loop) to each element separately.
Thank you for the warm welcome and the replies. Type instability is indeed the reason, now I get it.
The alternative syntaxes are also very welcome, thank you!