Re: Short Circuit Question

new topic     » goto parent     » topic index » view thread      » older message » newer message

>From: Daniel Kluss <codepilot at netzero.net>
>Subject: Short Circuit Question
>
>Can someone exlain why line to of the output actually tests both 1 and 3, 
>shouldn't just test 1?
>is it interpreted as ((1 or 2) and 3) or as (1 or (2 and 3)) ?
>Daniel Kluss
>

  It is interpreted as ((1 or 2) and 3). Logical AND and OR are at the same 
precedence level, so they are interpreted left-to-right. Of course, even if 
AND was higher than OR, then all three would have to be tested.


>----------output
>1 2 3 true
>1 3 true
>1 true
>1 2 true
>-----------program
>
>without warning
>function ptr(atom num)
>         printf(1,"%d ",{num})
>         return num
>end function
>
>if ptr(1) and ptr(2) and ptr(3) then puts(1,"true\n") else 
>puts(1,"false\n") end if
>
>if ptr(1) or ptr(2) and ptr(3) then puts(1,"true\n") else puts(1,"false\n") 
>end if
>
>if ptr(1) or ptr(2) or ptr(3) then puts(1,"true\n") else puts(1,"false\n") 
>end if
>
>if ptr(1) and ptr(2) or ptr(3) then puts(1,"true\n") else puts(1,"false\n") 
>end if
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu