C#

C#

Made by DeepSource

Non-short circuit logic is likely a mistake CS-W1017

Bug risk
Major

In a short-circuit logic, i.e. a logical OR operation (denoted via ||), the evaluation is stopped when a sub-expression in it evaluates to true whereas in a non-short circuit logic, i.e. a bitwise OR operation (denoted via |), the entire expression is evaluated. The highlighted condition is an example of non-short circuit logic and is likely a mistake and should have been a short-circuit logic instead.

Bad Practice

// Both `condition1` and `condition2` are evaluated.
if (condition1 | condition2)
{
    // ...
}

Recommended

// `condition2` is evaluted only if `condition1` evaluates to `false`
if (condition1 || condition2)
{
    // ...
}

Reference