Use of Goto inside an If:Then or other loop.
Since entering the TI community, i have been constantly informed that i cannot have a Goto inside a loop. However, this can be slightly limiting in terms of flexibility, so i set out to decide how it could be done... and i have succeeded.
If you have the program:
:Lbl 1
:While G=0
:GetKey->G
:If G=105:Then:Goto 2:End
:End
:Lbl 2
:[code]:Goto 1
you will notice that the program gets slower and slower, eventually giving off an ERR:MEMORY. So, how can you fix this? The answer is so simple it's been smacking me in the face for the past week. The TI-OS doesnt care where you end your If:Then statement, just so long as it gets ended at some point. So, knowing this, our program becomes:
:Lbl 1
:While G=0
:GetKey->G
:If G=105:Then:Goto 2:End
:End
:[code]:Goto 1
:Lbl 2
:End
:[code]:Goto 1
If you were to run this program, you would experience absolutely no slowdown. If you dont believe me, run any of the past 2 programs i have released, as both use this technique as a test.
you must also ensure that the only way the End can be accessed is through an If:Then, otherwise the TI-OS wont know what it is supposed to be ending, and will give out an ERR:SYNTAX
This is useful for certain repetitive programs, for example in a store program
:Lbl A
:If M <= 100:Then:Goto 2:End
:[code]
:Goto 1
:Lbl B
:If M <= 150:Then Goto 2:End
:[code]
:Goto 1
:Lbl 2
:End
:Disp "you dont have","enough money"
by using this method, you only save about 30 bytes for each item you have in the store, as you only have to enter the "you dont have enough money" message once, instead of once per item.
Since entering the TI community, i have been constantly informed that i cannot have a Goto inside a loop. However, this can be slightly limiting in terms of flexibility, so i set out to decide how it could be done... and i have succeeded.
If you have the program:
:Lbl 1
:While G=0
:GetKey->G
:If G=105:Then:Goto 2:End
:End
:Lbl 2
:[code]:Goto 1
you will notice that the program gets slower and slower, eventually giving off an ERR:MEMORY. So, how can you fix this? The answer is so simple it's been smacking me in the face for the past week. The TI-OS doesnt care where you end your If:Then statement, just so long as it gets ended at some point. So, knowing this, our program becomes:
:Lbl 1
:While G=0
:GetKey->G
:If G=105:Then:Goto 2:End
:End
:[code]:Goto 1
:Lbl 2
:End
:[code]:Goto 1
If you were to run this program, you would experience absolutely no slowdown. If you dont believe me, run any of the past 2 programs i have released, as both use this technique as a test.
you must also ensure that the only way the End can be accessed is through an If:Then, otherwise the TI-OS wont know what it is supposed to be ending, and will give out an ERR:SYNTAX
This is useful for certain repetitive programs, for example in a store program
:Lbl A
:If M <= 100:Then:Goto 2:End
:[code]
:Goto 1
:Lbl B
:If M <= 150:Then Goto 2:End
:[code]
:Goto 1
:Lbl 2
:End
:Disp "you dont have","enough money"
by using this method, you only save about 30 bytes for each item you have in the store, as you only have to enter the "you dont have enough money" message once, instead of once per item.