Shop OBEX P1 Docs P2 Docs Learn Events
Question about Repeat and Quit — Parallax Forums

Question about Repeat and Quit

karakikokarakiko Posts: 11
edited 2010-03-27 22:46 in Propeller 1
Hello forum,
I am using the Parallax Serial Terminal to send ASCII strings to run a routine, the routine is :
PUB LedOnOff( num,value )
 repeat
  test2.writeLed1(0,0) 
  test2.writeLed1(1,250)
  test1.writeLed(1,250) 
  test1.writeLed(0,250) 
  WaitCnt(OneSecond + Cnt)

when i am writting in PST LednOnOff the routine is running and the program is working good, but sometimes i need·to quit from this loop, how·can i do this ?

Thanks in advance,
Karakik

Comments

  • pullmollpullmoll Posts: 817
    edited 2010-03-27 15:09
    karakiko said...
    how can i do this ?

    With the quit instruction. It leaves the level of repeat you are in and continues as if the repeat condition had expired. A repeat alone has the condition "always", but quit still leaves the loop.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    He died at the console of hunger and thirst.
    Next day he was buried. Face down, nine edge first.
  • karakikokarakiko Posts: 11
    edited 2010-03-27 15:38
    Thanks , but how i can call quit to stop the repeat ?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-03-27 15:47
    Read the Propeller Manual section on the REPEAT statement and the QUIT statement. There are plenty of examples there.
  • pullmollpullmoll Posts: 817
    edited 2010-03-27 19:54
    karakiko said...
    Thanks , but how i can call quit to stop the repeat ?

    You will have some condition when to quit? If the name of that condition is test_quit, then you just do
    PUB LedOnOff( num,value )
     repeat
      test2.writeLed1(0,0) 
      test2.writeLed1(1,250)
      test1.writeLed(1,250) 
      test1.writeLed(0,250) 
      WaitCnt(OneSecond + Cnt)
      if test_quit
        quit
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    He died at the console of hunger and thirst.
    Next day he was buried. Face down, nine edge first.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-03-27 22:46
    You may need to do multiple tests if you're using nested repeat loops as I was in a recent project. I have a "background" process running that uses stacked repeat loops; the foreground can tell the process to terminate by setting a global flag; I had to include tests in both loops to get the correct behavior. It's not difficult, it's just a detail.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
Sign In or Register to comment.