Quote Originally Posted by GCDEF View Post
The only thing "completely wrong" in the OP's code is his decision to use an unsigned counter.
That is not so wrong after all. The size_type typedefs over the standard containers and sequences are unsigned types as well. Most implementations will have std::size_t and size_type to be the same (but it may not be guaranteed - I am not sure). Both are unsigned integral types - that's for sure.

So, there's nothing inherently wrong with using that kind of a loop. The only thing wrong is that he unknowingly expects that when his loop counter reaches 0, and is decremented, it will become less than 0 and hence break out of the loop. That is wrong!

Although, alternatives have been provided, here is a fix to that loop:
Code:
	for (std::size_t loop = obj.size() - 1; loop < obj.size() ; --loop)
	{
		std::cout << obj[loop] << "\n";
	}