Don't use count() in a loop.

Use do while so the count does not happen in a loop statement. This
makes the code linter happier.