On 2008-04-30, Philip Gage <philip@[EMAIL PROTECTED]
> wrote:
> In message <pURRj.3093$PM5.3083@[EMAIL PROTECTED]
>, Duke Normandin
><dukeofperl@[EMAIL PROTECTED]
> writes
>>set i=1,j=2,k=3
>>if i<j&k>j write "yes",!
>>
>>i _is_ less than j AND k _is_ greater than j
>>
>>so why is _yes_ NOT printed?
>>
>>The logical operator & tells me that both relational expressions must
>>be true in order for the _yes_ to be printed. That's exactly what it is,
>>so what am I missing? TIA......
> Left to right operator precedence.
> i<j is true so evaluated to 1
> 1&k is true so evaluates to 1
> 1>j is false so yes is not printed.
> to obtain the correct result the conditions should be in parentheses
>
> if (i<j)&(j>j) write yes.
>
> However an alternate would be
>
> if i<j,k>j write yes
>
> This is possibly preferred in that the command is broken into two
> commands, and the second one only executed if the first one is true.
>
> The reason for the preference is performance. The second condition is
> only evaluated if the first is true, so by putting the least likely
> condition first one can optimise the code.
>
> Optimisation should only be done when the code retains clarity, and when
> it is executed sufficiently often to justify the work.
Thanks for the great explanation! What is _your opinion_ of
"****d references" -- if you dare to go there. ;)
--
Duke Normandin


|