I think a while loop might be more readable here ...