wrote better loop condition