Operators/Logical And

From FizzFuzz

Jump to: navigation, search
Go back to Operators.

Logical and is a Boolean operation on any two data types. The operation is commutative and associative, and is indicated by a binary, infix && (two consecutive ampersands).

Contents

Notation

α && β

Where α and β are both variables, literals, or values of any data type or class.

Operation

If both α and β are true, then the whole thing will evaluate as true. Otherwise, it will evaluate as false. Note that it won't evaluate to the values true and false. The && operator, in FizzFuzz, is short-circuiting, meaning that, when a false value is encountered, && immediately evaluates to false.

Notes

In addition to being short-circuiting, as above, FizzFuzz's && operator also will return the last value it's evaluated. In a series of true values, this will return the very last values, while it will return the last false value if there is one.

Examples

int alpha = 1;
int beta = 2;
char gamma = 'c';
 
output << (alpha && beta && gamma); // Outputs "c", as it's the last value evaluated.
output << (alpha && null && gamma); // Outputs "null", as it's the last value evaluated.

See Also