[refactor] changed all determinate while-loops to for-loops