Use a for instead of a do while to avoid returning early