Changed while loop to a for loop in the main()