And to a lesser extent, what about a for loop with i<(n+1)? Would (n+1) get evaluated once at start of loop or at every iteration?
for(int i=0; i<(n+1); i++){
// Do something
}
for(int i=0; i<=n; i++){
//Do something
}
UPDATE:
As suggested by nearly everyone, I ran a simple test with three loop variations i
It would likely depend on whether or not the value of n was changing over the course of the loop. If not, I would think that any modern compiler would cache the value of n+1, rather than calculating it each iteration. Of course that’s not a guarantee, and with no optimizations, n+1 would be evaluated each time.
EDIT: To answer the title question, i < n vs. i <= n would have no noticeable difference (other than an extra iteration, assuming the n’s were equal in both cases.) CPUs have single ops for both comparisons.