'goto" gone from computer languages or is it!

Jim Battle frustum at pacbell.net
Thu May 12 23:02:20 CDT 2005


Ethan Dicks wrote:

> On 5/12/05, lee davison <leeedavison at yahoo.co.uk> wrote:
> 
>>>>Even BASIC has a call stack that will eventually overflow.
>>
>>>On a 6502 (PET, Apple II...) it's not that deep because of
>>>the 1-page stack. ISTR about 5 levels of GOSUBs were possible
>>>before you ran the risk of stack overflow, but it might have
>>>been as deep as 8.
>>
>>Assuming the stack is cleared by RUN then you can nest 40 to
>>50 levels of GOSUBs in most 6502 BAISCs.
>>
>>FOR ... NEXT is the stack hog, you can usually only nest that
>>15 deep or less.
>>
>>With C= BASIC you have lass room as the top 10 bytes or so of
>>the stack are reserved for float to ASCII conversion.
> 
> 
> Maybe that was it... MS BASIC on a C= PET, with subroutine calls and
> FOR/NEXT nested deep enough that one _could_ see the bottom.  I never
> did a GOSUB-only test, but ISTR having to design some stuff with stack
> depth in mind (I did a lot of stuff with Interactive Fiction/Adventure
> Games in the late 1970s in BASIC, then I learned 6502 assembly ;-)

Since we are about vintage computers here, I tried the following on a 
few emulators and real machines:

10 I=0
20 PRINT I:I=I+1:GOSUB 20

10 I=0
20 FOR J=1 TO 10:I=I+1:PRINT I:GOTO 20


Wang 2200 BASIC:                45 GOSUBs,   54 FOR loops
Wang 2200 BASIC-2:              61 GOSUBs,   61 FOR loops
Applesoft BASIC:                25 GOSUBs,   11 FOR loops*
TRS-80 48K Model III:         9596 GOSUBs,   **
HP87-XM BASIC:                 255 GOSUBs,   **
Sol-20 BASIC/5:                 33 GOSUBs,    6 FOR loops
Sol-20 Extended BASIC (48K): 11223 GOSUBs, 1978 FOR loops
IBM 5120:                       20 GOSUBs,  ***

* Applesoft: The test program for FOR loops didn't fail.  I had to nest 
11 FOR loops deep to find the limit.

** TRS-80, HP-87: BASIC apparently doesn't allow stacking FOR loops 
using the same index variable.  The program just runs forever, and I 
didn't feel like attempting hundreds/thousands of nested FOR loops manually.

*** IBM 5120: refused to run program and I didn't attempt to nest dozens 
manually






More information about the cctalk mailing list