0

I'm trying to identify the differences between the "Logical AND" and the "Conditional Logical AND" on the Boolean Logical Operators page.

The only difference I can see between them is that, in the first example below, the second operand is still evaluated even though the first operand is false (so the result will be false regardless of to what the second operand evaluates).

Whereas in the second example, the second operand is not evaluated because it will make no difference to the outcome:

bool a = false & SecondOperand();
bool a = false && SecondOperand();

I realise they are something entirely different when used with integers (bitwise shift and all that). But in a Boolean sense, is that the only difference and if it is, is there any reason to ever use & rather than &&?

Many thanks in advance,

  • 1
    does "when you want both sides to always get executed (unless an exception happens)" count? – Marc Gravell May 07 '20 at 16:28
  • 1
    Does this answer your question? [Usage of '&' versus '&&'](https://stackoverflow.com/questions/5537607/usage-of-versus) – Mohamed Sahbi May 07 '20 at 16:31
  • Hi both, thanks for taking the time to feed back. Yes it's as I thought - no great reason to use "&" for Booleans. Just worried that I was missing something obvious. Many thanks! :) – FredAndBarney May 07 '20 at 17:48

0 Answers0