0
NOT operator in C#
Hi. I'm making a Currency Convert for USD and EUR. I make the user type int to select currency conversion(1/2). But I wanted to make a while loop so when the user types something else, the program will ask for input again. It's working fine but now it keeps asking me for input for every number I type. Is my while loop not good? -while( !(currency == 1) || !(currency == 2)-
1 Answer
+ 5
The loop terminates when its terminating condition becomes false. When does it become false?
!A or !B ⥠!(A and B), and that is false if A and B is true, which is true if both A and B are true.
That means in your case, it terminates if currency is both 1 and 2. And that is never the case.
You want &&, I think. And !(x == y) is usually written (x != y).