Use range() instead of a while loop