Shop OBEX P1 Docs P2 Docs Learn Events
IF argument order of operations — Parallax Forums

IF argument order of operations

Mike GMike G Posts: 2,702
edited 2013-02-17 18:16 in Propeller 1
I'm curious about the order of evaluation in an IF statement. The snippet below is within an infinite loop. I'd rather not invoke the I2C bus, rtc.clockHour, on ever iteration, only if i == 100,000.
  repeat
  ...
      if(i++//100_000 == 0)
        if(rtc.clockHour == dhcpRenew)
          RenewDhcpLease
        i := 1

Given a logical AND, are the following two snippets equal? Will the condition return false if one of the conditions are false while not testing the other? Or are both conditions always tested?
     if(i++//100_000 == 0 AND rtc.clockHour == dhcpRenew)
        RenewDhcpLease
        i := 1
     if(rtc.clockHour == dhcpRenew AND i++//100_000 == 0)
        RenewDhcpLease
        i := 1

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-02-17 17:51
    Mike G wrote: »
    Or are both conditions always tested?
    Unfortunately all conditions are tested (left to right).
  • pedwardpedward Posts: 1,642
    edited 2013-02-17 18:00
    Generally speaking, the evaluation short circuits at the first non-match in most languages.
  • Mike GMike G Posts: 2,702
    edited 2013-02-17 18:16
    Unfortunately all conditions are tested (left to right).
    Thanks... got it
    Generally speaking, the evaluation short circuits at the first non-match in most languages.
    I should have prefaced with in Spin... My query stemmed from experience with other languages.

    Thanks all
Sign In or Register to comment.