use for instead of while loop