Hi, I am not able to reproduce your issue. at console i enter 1 and click enter button, i do not see error message. It seems some thing is wrong with your code, Can you provide the complete code of main method
public static void Main(string[] args)
{
int iValue1;
Console.WriteLine("Please enter first value: ");
iValue1 =
Convert.ToInt16(Console.ReadLine());
while (iValue1 > 1)
{
Console.WriteLine("Sorry value must be 1 or 0. Please re-enter value: ");
}
Console.ReadLine();
I thought earlier that you are getting this error when you enter 1 or 0, you have not mentioned explicitly when this error is coming.
Reason of your error is 'while loop' Say you entered 5 then while loop will keep on running as condition while (iValue1 > 1) always true
instead of while loop use If condition
As you have provided your code here is the solution: use do while instead of while loop as shown below
do
{
if (iValue1 > 1)
{
Console.WriteLine("Sorry value must be 1 or 0. Please re-enter value: ");
iValue1 = Convert.ToInt16(Console.ReadLine());
}
}
while (iValue1 > 1);