is there a reason to prefer a while to a foreach here?