In a “for” statement, should I use `!=` or `

for(i = start; i != end; ++i)

This is the “standard” iterator loop. It has the advantage that it works with both pointers and standard library iterators (you can’t rely on iterators having operator< defined).

for(i = start; i < end; ++i)

This won’t work with standard library iterators (unless they have operator< defined), but it does have the advantage that if you go past end for some reason, it will still stop, so it’s slightly safer. I was taught to use this when iterating over integers, but I don’t know if it’s actually considered “best practice”.

The way I generally write these is to prefer <.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)