With a sufficiently smart compiler, it is possible to get the best of both worlds. If the compiler can prove that the two loops have the same number of iterations, and that the two functions don't interfere with each other, then it can optimize them into one loop. I believe this is one of the tricks Haskell uses.