How to take multiple inputs into a list until a certain word is typed?
I'm trying to do a script that will take an integer and add it to a list. It will continue to ask for an integer and add it until you type 'exit'. At that time it will sort the list and give you the lowest and highest integer. I feel like a while loop will do this for me, but I'm unsure on the proper way to do it. The code below is what I have, but it simply stops after I enter the first integer. The main part that is screwing me up is trying to detect when someone types 'exit' and catch any exceptions. List<int> nums = new List<int>(); Console.WriteLine("Enter a number or exit: "); var input = Console.ReadLine().ToLower(); while (input != "exit") { nums.Add(Convert.ToInt32(input)); } nums.Sort(); Console.WriteLine("Your biggest number is -{0}- and your smallest number is -{1}-.", nums[nums.Count - 1], nums[0]);