Example:
if function1(input) && function2(input) {}
In this case would function2(input)
be executed if function1(input)
returns false?
What you are asking about is called Short Circuiting, and yes, Go does it.
In the language spec, it says that
Logical operators apply to boolean values and yield a result of the same type as the operands. The right operand is evaluated conditionally.
This means that, in your case, if function1
returned false, function2
would not be called.
No. Go uses standard conditional shortcut logic - the first false
result in a string of &&
conditions will stop evaluation of further conditions (because it cannot yield a true
result no matter what the other conditions are). Likewise, the first true
result in a string of ||
conditions will stop evaluation because it cannot yield a false
result no matter what the other conditions are.