Now imagine you have got a typo:
400 L=0:GOTO 290
This would be almost impossible to debug.
Re:GOTOphobia Considered Harmful (In C)
by thaumasiotes on Monday February 27, 2023 @04:06AM
(#34954454)
That would correspond to the following C:
/* 280 */
do_something();
for (;;) {
/* 290 */
/* display chart in blocks of 18 lines */
/* 400 */
L = 0;
}
when the correct code is this: for (;;) {
/* 280 */
do_something();
/* 290 */
/* display chart in blocks of 18 lines */
/* 400 */
L = 0;
}
The bug is that the call to do_something() precedes the outer loop when it should be inside the loop.Is that easier to debug in C than it is in the BASIC program? What's the difference?
Without looking at the post-program material, this isn't exactly a difficult question to answer.
Line 400 is preceded by some print statements:
So we have a prompt that says "press E to end, space to continue", and then branches one of three ways: if you provide no input, the prompt is shown again; if you provide an E, the entire program restarts from scratch, and if you do anything other than that, the count of lines drawn on screen is reset to 0 and the next 18 lines of the chart are drawn.We can assume that line 400 will be hit whenever a piece of chart is drawn to the screen.
The program's structure here is a nested loop: there is a loop between lines 280 and 400 (displaying the chart indefinitely, 18 lines at a time) containing another loop between lines 300 and 360 (displaying 18 lines of a chart, one line at a time).
Why is this supposed to be an example of spaghetti code?