Operator || represents a conditional OR.
myBoolVar will be true if any of isC, isP or isX is true.
He looks like | operator between boolean operands, except that if the left side evaluates to true, the right side will not be evaluated.
As for good practice, consider a more detailed semantic equivalent: -
bool myBoolVar; if (isC) { myBoolVar = true; } else if (isP) { myBoolVar = true; } else if (isX) { myBoolVar = true; }
In particular, consider which one you would prefer to keep. For the most part, I would expect people to consider terser myBoolVar = isC || isP || isX; myBoolVar = isC || isP || isX; more readable.
From the comments below, you can see that you are making the argument that programming is about simplicity, not "demonstration." I agree that programmers often try to compromise or deliberately confuse code for their own satisfaction - often to the detriment of the project. This is probably one of these cases not . I can call the variables clearer, and I could encapsulate it behind an appropriately named property, but I would definitely use the construction a || b || c a || b || c a || b || c over something more verbose.
If you feel that you have a clearer way to express this, share it with us and we can discuss it.
source share