"and" is a reserved word in the programming language Lua.

In the BNF syntax of Lua, it appears as a terminal atom in one substitution rule:
binopand
"binop" appears as a nonterminal atom in one substitution rule:
expexp binop exp

"and" is the conjunctive binary logical operator. Like the control structures, all logical operators consider "nil" as false and anything else as true. The conjunction operator "and" returns "nil" if its first argument is "nil"; otherwise, it returns its second argument. (Both "and" and "or" use short-cut evaluation, that is, the second operand is evaluated only if necessary.)

This makes the "and" operator a bit like the "if" statement. There are only 3 differences; "and" returns a value but "if" doesn't, the second operand of "and" must be an expression whereas the "then" branch of "if" is a statement, and "if" potentially has "elseif" and "else" branches.

There is one useful Lua idiom that uses the logical operator "and". It is
x = a and b or c
which should be read as x = (a and b) or c. This idiom is equivalent to
if a then x = b else x = c end
provided that b is not "nil".


Other systems do not use short-cut evaluation (a limited form of lazy evaluation), and both operands are always evaluated fully before the result of the "and" operation is determined. Yet other systems, nondeterministic systems, usually found in parallel processing environments, guarantee that the result of the "and" operation is logically correct, but does not guarantee that both operands are fully evaluated, it does not guarantee that either one in particular is evaluated (Lua guarantees that the first operand is evaluated), and it does not guarantee that an operand will not be only partially evaluated (Lua guarantees that the second operand will either be evaluated or not, with no in-between). Using impure functions or expressions with side-effects in nondeterministic systems is therefore considered harmful.

And, in other programming languages, the "and" keyword can have another meaning: a bitwise "and" on two numeric (usually unsigned integer) operands (giving another number, of the same type, as a result). A number may be considered an array of bits; in Eindhoven notation, any number (b) may be expressed as (+ : iZ : bi * 2i) - standard binary notation - each bi being either 0 or 1, thus making an array of bits. (For signed values, the sign bit is considered just another bit in the array; for integers, negative values of i need not be considered.) The "numeric and" performs the "logical and" operation on bits in corresponding positions in the two operands, and places the result of each "logical and" in the corresponding position in the result. In symbols, "b and c" evaluates to (+ : iZ : (bi and ci) * 2i).

The C symbol for "logical and" is && and the C symbol for "numeric and" is & (which is the same symbol used for dereferencing, the opposite of the * operator).