A better way to break the loop