this logic is confusing.  consider using `whilst`.