I want to use multiple conditions in while loop:
Console.WriteLine("Select an action to perform\n");
int n1 = Convert.ToInt32(Console.ReadLine());
do
{
Console.WriteLine("Insert a valid method\n");
n1 = Convert.ToInt32(Console.ReadLine());
}
while ((n1 == 1) || (n1 == 2));
Console.WriteLine(n1);
Console.ReadKey();
In here I want to check the value n1
is equals to 1 or 2. Until the user enter n1 or 2 this should loop. The thing is I can get this to working if im using just one condition but cant get this working when there are 2 conditions. Also how to equal these values to another string?
Ex:
while ((n1 == "one") || (n1 =="two"))
I think theres something I didnt understand about || (OR) operator
. I read few solutions yet I couldnt figure it out.