Make loop termination more explicit.

This is a follow-up to this commit https://github.com/danmar/cppcheck/commit/e7754be3160fd8a709d8c949cd8fe92d17de8e88