@yfede when you are using & you are indeed using bitwise operators to operate with 2 booleans rather than using “logic operations/truth tables”. The booleans are converted to integers 0 (if false) and 1 (if true) and applies a bitwise operation:
- X & 1 = 1
- X & 0 = 0
(No matter the value of X, but in our case X will be only 0 or 1 as it’s just a boolean)
On the other hand the always used && (and) as I understsand doesn’t need to evaluate the 2nd term if the first one is false as it’s making a logic operation, while in the & case as you are doing “normal operations” it evaluates every term.
The thing is that if you want to always evaluate one condition you can just put it first, like:
if (mustEvaluate && conditionB) ...
But if for some very specific reason you must evaluate both conditions (i.e both are functions that not only return a boolean but also do other needed logic) then you can use &. I get many will dislike using it and prefer doing all this stuff in another way as it’s less readable, but it’s just an option.
But I bet someone else can shed some light into the why && vs & work different
TLDR: && = and, & = bitand