changed for loop to while loop to print each line