modify the loop terminal condition