for loop instead of while loop