Hacker News new | ask | show | jobs
by Someone 261 days ago
> Mmm. IIRC, usually the compiled NEXT statement would store the pointer to the corresponding FOR statement, so you don't need an additional stack for loop depth during the execution

I think you do. Apart from common sense, nothing forbids one from writing stuff like

  100 for i = 1 to 10
  110 if i = 4 gosub 100
  120 print i
  130 next
  140 return
I think many basics also allowed changing that goto 100 to goto 200 and adding

  200 for j = 1 to 4
  210 print i
  220 print j
  230 next
Yes, things would likely end badly, but the basic interpreter would not be smart enough to reject such programs. Its editor didn’t even guarantee that a for statement had a corresponding next or vice versa; all it guaranteed was that the program consisted of a list of lines that each in isolation are valid basic code.
1 comments

This is some beautifully horrible spaghetti, well done. It's like I'm eleven years old and barely understand what's going on in the computer again.

I just fired up VICE and my virtual c64 happily ran both of those, if throwing an "out of memory" error after about five runs through the first one counts as "happily".