It didn't take long for me to be a "never GOTO, never ever" guy once we started to see structured BASIC implementations displace unstructured BASIC implementations.
Since I started working on BASIC Anywhere Machine back in December 2020, I've really come to appreciate the use of GOTO with line labels (instead of line numbers) in a couple of scenarios.
BASIC Anywhere Machine (aka "BAM") links:
Always being weary, of course, of not creating spaghetti code, here are two scenarios in which I find GOTO really practical. When do you find GOTO useful and acceptable ?
Loops involving a lot of code
For the following blocks of code:
- WHILE ... WEND
- WHILE ... LOOP
- DO ... LOOP
- DO WHILE ... LOOP
- DO WHILE ... WEND
- DO LOOP ... WHILE
- DO LOOP ... UNTIL
Skip over a block of code
In some circumstances, it makes more sense to me to have an IF that skips a block of code, rather than have an IF condition be satisfied to execute that block of code (and exclude the block otherwise).
...
No comments:
Post a Comment