another way to make it with for instead of while