fix the process of breaking from for-loop