Jeff Westman wrote:
> Basic question on using '&&' vs 'and'. I see that '&&' has higher
> precedence than 'and', but why does
>
> print 1 && 1 && 0;
> print "\n";
> print 1 and 1 and 0;
> print "\n";
>
> return
> 0
> 1
>
> I would have expected both statements to return 0.
Hi Jeff.
'print' without any parentheses is a list operator, which
gets evaluated after almost anything else to its right,
except 'and', 'or' and 'xor' which have an even lower
priority. So
print 1 && 1 && 0
evaluates as
print(((1 && 1) && 0))
while
print 1 and 1 and 0
evaluates as
((print(1) and 1) and 0)
In fact the compiler will optimise the former expression
to a simple
print(0)
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]