91
TI-BASIC / Re: scripts and code snippets
« on: April 23, 2009, 05:40:56 pm »
I used a similar method in a number of my programs.
You want to make sure that your "sub-program" is located at the top of the program because the time it takes for the interpreter to locate the Lbl is directly proportional to its location from the top of the program.
The main advantage of this method is you can send information via Ans, and you don't use any variables.
Start of program:
:Code
:More code
:Goto 0 (you have to skip to the main code since this next part will be the sub-programs)
:Lbl 1
:woot!
:subprogram
:0 (needed so that the loop will end)
:End (normally this would be extraneous, but we induced a temporary memory leak that this will fix)
:Lbl 0 (start of main code)
:code
:stuff
:the last digit of pi is 0
:lets run a sub-program
:1 (can be any non-zero value. This is useful if you want to send information via Ans to subprograms)
:Repeat Ans
:If Ans
:Goto 1
:1
:End
:back to main code
:example finished.
You want to make sure that your "sub-program" is located at the top of the program because the time it takes for the interpreter to locate the Lbl is directly proportional to its location from the top of the program.
The main advantage of this method is you can send information via Ans, and you don't use any variables.
Start of program:
:Code
:More code
:Goto 0 (you have to skip to the main code since this next part will be the sub-programs)
:Lbl 1
:woot!
:subprogram
:0 (needed so that the loop will end)
:End (normally this would be extraneous, but we induced a temporary memory leak that this will fix)
:Lbl 0 (start of main code)
:code
:stuff
:the last digit of pi is 0
:lets run a sub-program
:1 (can be any non-zero value. This is useful if you want to send information via Ans to subprograms)
:Repeat Ans
:If Ans
:Goto 1
:1
:End
:back to main code
:example finished.