used for loop instead of while