Here's an example:

Code:

...
:code
:If 0:Then
:Lbl N
:21->K
:End
...
:code
...
:Repeat K=21
:getkey->K
:If K=12
:Goto N
:End
:code
...

It goes to a label inside an If-Then statement, satisfies the condition, and ends the loop. Very Happy
Very good! That's the method I usually use in such a situation; the use of the If 0 is particularly optimized imho.
It's been mentioned in many places many times. Why 21->K in the If...Then?
So it won't loop back to the Repeat.
But repeat checks the condition at the end of the loop. It will always be executed at least once.
Exactly. But when it reaches the End after the label I don't want it to return to the loop.
Yeah, if you want it to check before the loop starts, then use While, since it checks before looping.
something1990 wrote:
But repeat checks the condition at the end of the loop. It will always be executed at least once.


He meant so that when it gets to the "end" immediately following that line. If k != 21 when it hits that end, it will jump back to the Repeat. The TI-Basic parser is too stupid to understand that it has jumped out of the Repeat loop, hence the problem of memory leaks in the first place.

Code:
:If 0
:Then
:Lbl N
:21->K
:End :D
:While K!=21
:getKey->K
:If K = 12
:Goto N
:End

EDIT: I see what you mean Kllrnohj. It would work that way. But then he could just say Repeat K=12 instead.
Wow something, way to completely break the code (not to mention have syntax errors) The inital code block posted is completely correct, and will function as expected in that [code] is only executed after a keypress. The repeat is correct and the 21->k is correct.
That's why I put the edit beneath the code block right before you posted that message.
how bout this: We don't use lbls and Gotos, and viola! No memory leaks caused by them!

If you want to jump around a program, the best bet to do so I have found is to use While loops, within a main While loop. This way, you simply change the value of the While loop, and it totally ignores everything until it finds the one it wants, or exits the program, if it cannot find that value...
Repeate K=12 will only work if you are only checking for one keypress. Tell me, when have you ever made a game/program that uses GetKey (aside from a pause) and only checked for one keypress? Not to mention he is checking for TWO different keypresses, and Repeat K=12 would only check for 1
unless you are making something to "lock up" the keyboard, then there is no application that I can think of...
That was just an example.
Eh, you can just use the sum( or max( trick to get around that if you don't feel like a multipart conditional.
I knew this topic was mentioned previously. Link
Well, it is generally not considered good coding practices to use Lbls and Gotos, since they can slow a game down a ton. And if you find alternate ways of jumping around a program without the Goto/Lbl stuff, it usually makes the program/game run faster.

Just something to think on. Smile
For example, that program that I made that was entirely labelless BASIC. Hmmm, which one was that again?
Well if you really need a label (e.g. for new game) you can use this technique.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement