True AND False or False AND True type of condition in a more elegant way?
Solution 1:
If your objective is to avoid repeating #samecode
, you may make use of the Exclusive OR (AKA, XOR) operator as follows:
if (bool1 ^ bool2) // <-- If bool1 is true or bool2 is true but not both.
{
if (bool1)
{
// #different code1
}
else
{
// #different code2
}
// #samecode
}