Shop OBEX P1 Docs P2 Docs Learn Events
Exit of repeat with two conditions — Parallax Forums

Exit of repeat with two conditions

UnsoundcodeUnsoundcode Posts: 1,532
edited 2007-12-26 23:51 in Propeller 1
Hi to all, what would be the best way to to write a repeat loop that I can exit based on a value condition or elapsed time condition.

This is kind of what I want

repeat
·· some code
until value==x or time_elapsed==100mS

probably simple but I can't get it

thanks in advance

Jeff T.
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-26 23:38
    What you wrote is what you need. You do have to define what you mean by "time_elapsed". Here's an example from FullDuplexSerial:
    PUB rxtime(ms) : rxbyte | t
    
    '' Wait ms milliseconds for a byte to be received
    '' returns -1 if no byte received, $00..$FF if byte
    
      t := cnt
      repeat until (rxbyte := rxcheck) => 0 or (cnt - t) / (clkfreq / 1000) > ms
         ?long[noparse][[/noparse]def#randomSeed]
    
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-12-26 23:51
    Thank you Mike, you hit the nail on the head. I have been using FullDuplex.spin I now realize that FullDuplexSerial.spin is a more recent version.

    Jeff T.
Sign In or Register to comment.