@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