Example code follows:
bool result;
result = Operation1();
result &= Operation2();
result &= Operation3();
return result;
The intention is to ensure that, if any of the functions returns false, the functions that follow are not called. Is this syntax correct or do I need to do result = result && Operation2();?
If you mean a logical “and” rather than bitwise (I suspect so, since you’re using a
bool), use short circuiting:The functions will be evaluated left-to-right until one of them returns
false, then the rest will not be evaluated.