Shop OBEX P1 Docs P2 Docs Learn Events
Is "repeat until not" better, worse or the same as "repeat while" — Parallax Forums

Is "repeat until not" better, worse or the same as "repeat while"

dbpagedbpage Posts: 217
edited 2014-01-02 23:06 in Propeller 1
Consider the following statement:
repeat until not lockset(namelock)

Does the above statement require more, less or the same execution time and memory than the following statement?
repeat while lockset(namelock)

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-01-02 15:47
    Code space and execution time are two things you can check on your own. For code space, just hit F8 in the PropTool to see how much is required for each version. For execution time, use two readings of cnt, subtracting the earlier one from the latter one to get the duration.

    -Phil
  • kuronekokuroneko Posts: 3,623
    edited 2014-01-02 15:59
    re: execution time, it's a bit tricky with polling loops as it depends on when the lock state changes to trigger the exit path, e.g. changing shortly after the check adds another loop run before you can exit. In your case I'd stick with the while but write it like this (less space):
    repeat
      while lockset(namelock)
    
  • AribaAriba Posts: 2,690
    edited 2014-01-02 23:06
    BST can generate a listing of the resulting bytecodes.
    Here is the output a bit simplified:
    repeat until not lockset(namelock)
    
    Addr : 0018:       36     : Constant 2 $00000001
    Addr : 0019:       2A     : LockSet(Id) Push
    Addr : 001A:       FF     : Math Op NOT   
    Addr : 001B:       0B 02  : jnz 001F  +2
    Addr : 001D:       04 79  : Jmp 0018  -7   
    
    
                       repeat while lockset(namelock)
    
    Addr : 001F:       36     : Constant 2 $00000001
    Addr : 0020:       2A     : LockSet(Id) Push
    Addr : 0021:       0A 02  : jz 0025   +2
    Addr : 0023:       04 7A  : Jmp 001F  -6   
    
    I would say that the WHILE version is faster because UNTIL NOT needs one bycode more. The other bytecodes are similar.

    Andy
Sign In or Register to comment.