by colejohnson66 · 10y ago · 0 comments
10 PRINT "1"
30 PRINT "2"
20 GOTO 10
What would print out? Just a bunch of "1"s or "12"s?The thing is that basic programs were not entered through a 2D text-editor per rather line per line. You would type "LIST" to re-read the whole program you typed so far, with the lines in the correct order. Then, you would enter a line starting with a number. It would overwrite any existing line with the same number.
Typically, a way to correct the program you wrote would be to type:
30
15 PRINT "2"
(replace the line 30 by an empty line, and insert a line number 15)
You can get around that with some flags, but its more of a pain than its worth.
We tend to go by hundreds for programs, and we have a renumber command, but using it is the nuclear option because it will break goto line number references from outside programs (yeah, that's a very common thing in this language)
17 GOSUB 5500 LIST
command, the interpreter would return 10 PRINT "1"
20 GOTO 10
30 PRINT "2"
You don't have to type LIST to reorder the lines, that just shows the re-ordering to you. If you didn't type LIST, but did type RUN (with the "unordered" listing) the interpreter would run each line in sequence of line number.If you ran out of line numbers you could sometimes RENUMber the listing.
Here's Stackoverflow:
This question is marked as a duplicate: http://stackoverflow.com/questions/2435488/why-basic-had-num...
Here's the closed question it's marked as a duplicate of: http://stackoverflow.com/questions/541421/why-did-we-bother-...
char** lines = malloc(...);
lines[10] = &line1;
lines[30] = &line2;
lines[20] = &line3;
Then when executing, it starts at `lines[0]', sees nops, gets to `lines[10]' and runs it, sees more nops, gets to `lines[20]' and jumps to `lines[10]'. All the while ignoring `lines[21]' and up.I escaped the "permanent brain damage" that Dijkstra complained about that era of BASIC producing, but I understand where he's coming from now and don't begrudge him the slight hyperbole. It was a language where there were so many accidental complexities that there was virtually no prayer of someone penetrating through to the essential issues, using Fred Brook's definitions of accidental/essential. You're not learning anything useful while you're manually renumbering lines because you used up everything between 15-20 and fixing up the GOTOs. (I never had anything with RENUM support.)
10 PRINT "1" 20 GOTO 10 30 PRINT "2"
The reason this is allowed is because it let you rewrite existing programs; if you later entered
10 PRINT "Hello World"
It would replace the original line 10 and use this one instead.