More efficient to check this at the end of the loop.