Shop OBEX P1 Docs P2 Docs Learn Events
Spin Newbie Question — Parallax Forums

Spin Newbie Question

Tim CreedTim Creed Posts: 4
edited 2009-12-05 16:10 in Propeller 1
As a newbie to the Prop, I have what I'm sure is a simple question. I'm in a repeat loop with a WHILE conditional statement that exits the loop upon a specific pin input state. It then goes into a second conditional repeat loop that (at some point) I want to exit and return to the first loop. How do I get back to the first loop? Something like a JUMP command in assembly language.

Comments

  • LeonLeon Posts: 7,620
    edited 2009-12-05 15:29
    QUIT?

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
  • heaterheater Posts: 3,370
    edited 2009-12-05 15:39
    The way that you have described it it looks to me like:

    repeat
       bla bla
       bla bla
    while somecondition
    
    repeat someothercondition
       bla bla
       bla bla
    
    



    Now when the second loop exits you want to start at the first. You could just add another repeat loop around the whole thing:
    repeat
        repeat
            bla bla
            bla bla
        while somecondition
    
        repeat someothercondition
            bla bla
            bla bla
    
    



    Do I have the right picture in mind ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • heaterheater Posts: 3,370
    edited 2009-12-05 15:41
    Be careful with the indentation.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Tim CreedTim Creed Posts: 4
    edited 2009-12-05 15:51
    Sure, simple enough. I was thinking more along the lines of calling subroutines, but a nested repeat should do the trick. Thanks for the suggestion.

    TC
  • heaterheater Posts: 3,370
    edited 2009-12-05 15:58
    I tend to get my indentation in a mess if it's more than a couple of levels deep so generally end up splitting the code into separate methods, something like:

    PUB
      repeat
         a_method
         another_method
    
    PRI a_method
        repeat
            bla bla
            bla bla
        while somecondition
    
    
    PRI another_method
        repeat someothercondition
            bla bla
            bla bla
    
    



    Probably a bit slower in execution though.

    By the way, welcome to the wonderful world of propelling!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Tim CreedTim Creed Posts: 4
    edited 2009-12-05 16:10
    Thanks, I'm really enjoying it so far. Spin is an easy shift from an AV control system that I've been programming for years. I've been using SX chips occasionally, programming in assembly. The Props architecture sure beats the heck out of dealing with interrupts.

    Regards,

    TC
Sign In or Register to comment.