added else to while loop