Q:

Why do c++ programmers use != instead of <

In c++ primer, pg 95 the author says that c++ programmers tend to use != in preference of < when writing loops. 
for (vector<int>::size_type i = 0; i != 10; ++i) is preferred instead of 
for (vector<int>::size_type i = 0; i < 10; ++i) 

I read the same thing in accelerated c++. Can someone explain the rationale behind this

A:

When using some kinds of STL iterators (those that aren't random access), you must use !=:
for (map<int,int>::iterator i = a.begin(); i != a.end(); ++i) ...

However, I don't see any reason to prefer != for well-ordered scalar types as in your example. I would usually prefer < for scalar types and != for all iterator types.

A:

It's a habit for generic programming; for example, you can easiely use < with indices, but you cannot use that with all iterator types. A list iterator cannot efficiently implement < - however, != can be implemented for even the simplest of iterator types. Therefore, it is a good habit to always use the most generic comparison - it makes your code more resilient to change.

A:

Think of the case when one have to increment by lets say 3 instead of 1.
for (vector<int>::size_type i = 0; i != 10; i+=3)

This will run forever since it will skip 10 and go to 12 instead and increment forever.
for (vector<int>::size_type i = 0; i < 10; i+=3) 

This will work fine in this case too. So != is not always a good choice.

