How does this loop exit when it hasn't been cancelled?