Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Hi

I've a problem with WHILE stack (I've not tested but it's likely the same issue with FOR stack) when exiting prematurely a WHILE..WEND loop  using a branching statement that transfers execution outside the loop (GOTO, RETURN, possibly RESUME), that is, not going explicitly through WEND statement. It appears that current WHILE frame is not popped from the stack and remain active, and that could cause a WHILE stack overflow quickly (WHILE stack size is currently 64 slots).

Here is a simplified example of my case, I've a subroutine in line 100 that will skip lines in file until an empty line has been found:

5 OPEN "data.txt" FOR INPUT AS #1
10 FOR i=1 to 100
20     GOSUB 100    ' Read file up to next empty line
30 NEXT
40 END

100 WHILE NOT EOF(1)
110     LINE INPUT #1, l$
120     IF L$="" THEN RETURN    ' Found
130 WEND
140 PRINT "EOF reached, no empty line found!"
150 STOP

When running this on a file containing more than 100 empty lines, it ends with "Out of memory in 100", and looking at interpreter state in Thoreau machine explorer:

Stacks: GOSUB 1, FOR 1, WHILE 64, handlers 0, IF 0

Since there is no "EXIT WHILE" or similar statement in legacy basic to provide a clean way to exit prematurely, a forced transfer of execution outside the loop is more or less the only way to quit the loop...