Q:

Logical Exclusive OR's vs Conditional Logical OR's Within An For Loop

Recently I have been working on a project that requires a loop to run x amount of times. Simply wanted to exclude certain output x values.
Bellow is an example of what I THOUGH would work:
// Create a 1-58 Loop
for (int n = 1; n < 59; n++)
{
    // Exclude Values
    if (n != 2 || n != 11 || n != 16 || n != 40)
    {
        // Display Data
        Console.WriteLine(n);
    }
}

The operation n != 2 || n != 11 || n != 16 || n != 40 Under any normal situations would exclude the values that do not equal != value x. However this does not work and still renders all values and ignores the operation once a or statement || is introduced.
Bellow is a solution I found after playing around for a bit:
// Create a 1-58 Loop
for (int n = 1; n < 59; n++)
{
    // Exclude Values
    if (n == 2 ^ n == 11 ^ n != 16 ^ n == 40)
    {
        // Display Data
        Console.WriteLine(n);
    }
}

So my question is why does the Logical exclusive || not work in a for loop but a Conditional logical ^ does? I'm pulling my information from this wiki. If i'm wrong about something please have no hesitations to correct me!

A:

^ is the logical exclusive OR, while || is the conditional logical OR. Exclusive OR is different than OR in that exclusive OR requires that one AND ONLY ONE of the conditions evaluates to true, whereas a conditional OR will also return true if both conditions evaluate to true.
Also note that the conditional OR (||) will return as soon as any condition evaluates to true (evaluated from left to right); no other conditions are evaluated since they would have no affect on the outcome (this makes it different than the | operator, where all conditions are evaluated).
Let's take a look at the statement that works:
if (n == 2 ^ n == 11 ^ n != 16 ^ n == 40)

If we break this down for one of the values we want to exclude, say 2 for example, we have:
if (true ^ false ^ true ^ false) =>
       \   /      /       /
        \ /      /       /
if (   true ^ true ^ false     ) =>
          \   /       /
           \ /       /
if (      false ^ false        ) =>
              \   / 
               \ /
if (          false            )

Then let's look at the condition that doesn't work and now we see why:
if (n != 2 || n != 11 || n != 16 || n != 40)

For the number 2, this becomes:
if (false || true || true || true)
         \   / 
          \ /
if (     true                    )     // evaluation stops at the first `true` result

So what else can we do in this situation? Well, we can swap the || operator with the && operator (which is the conditional logical AND operator), which only returns true if both conditions evaluate to true (and it also short circuits if any condition returns false, since no further evaluations are necessary).
Let's take a look:
if (n != 2 && n != 11 && n != 16 && n != 40)

For the number 2, this becomes:
if (false && true && true && true)
         \   / 
          \ /
if (     false                   )     // evaluation stops at the first `false` result

