Personally, I stand by the Case Against Goto: [size=78%]http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF[/size]
...but...Quoth Xeda:Personally, for TI-BASIC and many other languages, I find Goto is excellent. Having written several programming languages and evaluating the code for the TI-BASIC parser, Goto has one main disadvantage and one main advantage, if used properly, and one massive advantage if used improperly like a pro, and one disadvantage if used improperly like a new programmer:
Speed wise, in TI-BASIC, Goto will be slower than While, Repeat, and For(. This is because the BASIC parser stores data in its operator stack telling precisely where to jump upon looping. If I remember correctly, it stores the variable name, and the offset into the variable for where the loop starts. This is still pretty slow, and there are more complicated things that happen, too, but it basically lets the parser use a look-up table (LUT) for loops. Gotos on the other hand must search for the label in the program. If the label is near the end of a program that is >10000 bytes, for example, it will be noticeably slower jumping there than to the beginning. However, this consumes no memory.
There is a misconception that Gotos and Lbls can cause memory errors. This is not true. It is like saying guns kill people. It's not true. They may help, but ultimately, it is somebody else abusing them that causes it. In reality,
While, Repeat, and For( cause the memory leaks. Remember how I said that they push data onto an operator stack? That data only get removed on completion of the loop. If you use Goto to improperly exit the loops, then that data doesn't get taken off
not necessarily true; see below and reentering that loop causes it to push again, and again, and again, eventually making you run out of RAM.
Somebody who is versed enough in the TI-BASIC language knows that this can actually be useful for creating a structure not included in TI-BASIC, but should have been -- subroutines. The parser removes an item from the operator stack once it reaches an End. So what you could do is a complicated rebranching of a While loop using Goto:
While A>0 If remainder(A,2 Goto 1 / | / | /---------- | Lbl 1 | Disp 1 Disp 0 int(.5A→A .5A→A End End
*btw, formatting got off here
Looking at it this way, you see that it won't actually cause a memory leak because the parser doesn't care where or when it comes across an End. As long as it does, reach one, it will jump back to the start of the loop. However, in actual BASIC code, because it is linear, it might look something like the following:
While A>0 If remainder(A,2 Goto 1 Disp 0 .5A→A End Lbl 2 <<do stuff now that the loop is over>> Lbl 1 Disp 1 int(.5A→A End Goto 2 ;in case A becomes 0 because of this branch, it doesn't loop back, so we have to manually jump there.
Looking at it this way, you see that it won't actually cause a memory leak because the parser doesn't care where or when it comes across an End. As long as it does, reach one, it will jump back to the start of the loop. However, in actual BASIC code, because it is linear, it might look something like the following:
While this is by no means an efficient application of this idea, here is a program where I used that trick quite a bit to make a subroutine for sprite drawing, saving, and items menu so that I could call the routine at any point in my program without using sub programs or rewriting the routine.
Needless to say, I think Lbl and Goto are very useful. They shouldn't be used in places where While, Repeat, and For( are more efficient, but in TI-BASIC, where efficiency is key, Goto has its place.[size=78%]
...and, in an effort to be on topic, my favorite command is seq(), with the ability to create lists of all kind, to be manipulated in many ways. It's very versatile.[/size]