Shop OBEX P1 Docs P2 Docs Learn Events
repetitive routines? bs2 — Parallax Forums

repetitive routines? bs2

Gumby1108Gumby1108 Posts: 6
edited 2011-04-14 18:07 in BASIC Stamp
Hi all.

I'm doing a project currently that involves alot of repeating phrases which aren't arranged in a way that "do... loop" would be practical (at least as far as I know). I'm using the BS2 which I got from my school, and my program quickly filled up all of the memory. Is there a way that I could consolidate these individual repetitions into a single phrase, which i could then use repetitively in lieu of the weighty original? If there is, could someone in the know give me the most elementary tutorial (preferably in layman's terms - I'm new to this).

Thanks a bundle!

Comments

  • vaclav_salvaclav_sal Posts: 451
    edited 2011-04-14 17:32
    This is a job for Superman!
    Just kidding.
    Any sequence of commands can be put into subroutine function and then simply called from other function.
    Same as Main; subroutine can have varaiables generally set before the subroutine is called.
    Check GOSUB, label and RETURN in Help or manual.

    Note function of RETURN and limitation of nesting 4 subroutines.

    Example
    Test VAR Word
    Main:
    Test = 10
    GOSUB Subroutine_1
    GOSUB Subroutine_2
    END

    Subroutine_1
    DEBUG ? Test
    Test = 20
    GOSUB Subroutine_2
    Test = 30
    GOSUB Subroutine_2
    RETURN

    Subroutine_2:
    DEBUG ? Test
    RETURN

    Vaclav
  • Gumby1108Gumby1108 Posts: 6
    edited 2011-04-14 18:07
    thanks alot, that really helped tremendously :)
Sign In or Register to comment.