There is no general answer for this, especially on modern processors.
In theory
Theoretically, the less branches you have in your code, the better. Since the second statement repeats branches once per iteration of the loop, you need more processing time and therefore less efficient.
Almost
Modern processors perform the so-called branch prediction. This means that they are trying to figure out in advance if the branch is taken. If the prediction is correct, the branch is free (free, as in 0 CPU cycles), if it is incorrect, the CPU must reset its execution queue, and the branch is very expensive (as in more than 1 CPU cycle).
In your specific examples, you have two types of branches, those for the loop and those for the if . Since your condition for if does not change and the cycle has a fixed number of executions, both branches are trivial to predict for the branch prediction mechanism, and you can expect both alternatives to work the same.
In coding practice
Performance indicators rarely have an impact in practice (especially in this case due to branch prediction), so you should choose the best coding style. And I would consider a second alternative to be better in that regard.
source share