Can someone explain the difference between the or operators in c#

I am new to c# and trying to create just a small command line game
I am trying to use a while loop that will keep iterating if the user does not type -1 to quit
or type the correct number but the statement is not validation as intended
Can someone help explain why the while loop does not stop when either of these conditions are false


https://replit.com/@ben-spencer?tab=status

 while (user_inp != -1 || user_inp == correct_num)

Hi @ben-spencer!

I’m not a C# developer, but from my knowledge of other languages, you are using || instead of &&. In this case || only needs one condition to be true, but as you said

which requires &&, which can only be true if both conditions are true.

Edit: Tested it and it seems to work correctly now.

3 Likes

You used || instead of &&. The difference between those is that || is an or, which means it only needs one condition to be met, while && requires both conditions to be met.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.