Andy Anderson wrote:

> I would say that this is because the "operand" && is "ANDING" the numbers.
> Therefore the response the the line print 1 && 1 && 0; would be a 0. Since the
> line is a "mathematical string" it is performed left to right (1 && 1 = 1, 1 &&
> 0 = 0).
>
> Hope this helps.
>
> Have a great day;
>
> Andy

Hi Andy,

Right answer, wrong question.  The 0 result was expected.  The first statement:
print 1 && 1 && 0;
parses as:
print ((1 && 1) && 0);
The result is pretty much what we would expect.  The one that gets tricky in this case 
is:
 print 1 and 1 and 0;
which parses as:
((( print 1) and 1) and 0);
when the interpreter successfully prints '1', the first statement returns 1, so we 
have:
(1 and 1) and 0;
The boolean operation in the first and succeeds, so we have:
1 and 0;
which of course evaluates to 0, which is the return value of the overall statement, 
but which is never used.  the overall statement is a constant--"dead code" that does 
nothing at all

Both statement evaluate false.  In the second statement, the printing is done before 
the statement is evaluated, because the function call takes a higher precedence than 
and.

HTH,

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to