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 offnot 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:
Lbl 1 |
Disp 1 Disp 0
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:
<<do stuff now that the loop is over>>
Goto 2 ;in case A becomes 0 because of this branch, it doesn't loop back, so we have to manually jump there.
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:
(Note, some assembly was used, but not for sprite drawing or any of that stuff.)
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.