Shop OBEX P1 Docs P2 Docs Learn Events
FOR/NEXT and GOSUB(PULL address from Stack) — Parallax Forums

FOR/NEXT and GOSUB(PULL address from Stack)

hmlittle59hmlittle59 Posts: 404
edited 2008-02-04 10:55 in General Discussion
Hello Everyone

I've got myself in a pickle!!!

I am within a FOR/NEXT loop and want to EXIT. The original flow of this routine was OK, but I added a PIN checking routine and want to EXIT upon a certain condition, back to the main calling routine. This routine is buried in the code by a couple of SUB-Routines and I want to be able to PULL a couple of return addresses "OFF" the stack. Is this possible from within PBasic?

1) I'm within my program by 2 gosubs routines
2) upon a certain condition i want to exit back to the main routine
3) does Pbasic allow me to PULL RETURN addresses off the stack?(or some other work around)

Note: the normal flow of the program was ok, I just wanted to add a routine to get me back to the main menu, other the reset.

thanks for any help

hmlittle59

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-02-03 02:11
    hmlittle -

    PBASIC 2.5 brought us the EXIT command. Take a look at it and see if it meets your needs.

    To answer your question directly, there is no way to arbitrarily "pop" the RETURN stack in PBASIC (thankfully!). You can exit from a FOR ... NEXT loop any time you want, so long as you re-enter by the FOR statement, for re-initialization, the subsequent time through it.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There is no pleasure in having nothing to do;
    the fun is in having lots to do, and not doing it!
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2008-02-03 02:59
    To add to what Bruce said:

    my_sub:
    FOR ix=1 TO 1000
      FOR jx=1 TO 1000
         flag=in0  ' exit condition is in0=1
         IF flag=1 THEN EXIT
      NEXT
      IF flag=1 THEN EXIT
    NEXT
    RETURN   ' exits end up here
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • hmlittle59hmlittle59 Posts: 404
    edited 2008-02-04 10:55
    Thanks for the help....I'll try it

    hmlittle59
Sign In or Register to comment.