3 ms·
This is pretty good, but not exactly written in a totally fulfilling manner. I'm not certain why this wouldn't just print PI forever. 2 LET PI = 3.14 : GOSU
by trentlott 12y ago
This is pretty good, but not exactly written in a totally fulfilling manner.
I'm not certain why this wouldn't just print PI forever.
2 LET PI = 3.14 : GOSUB 20 : LET MONEY = MONEY + 1
20 PRINT PI : RETURN
101 PRINT “I have”; MONEY ;”dollars.”
Outputs:
RUN
Happy Birthday Mrs. Bits
3.14
3.14
?RETURN WITHOUT GOSUB ERROR AT LINE 20
Which is explained (to children) like this:
"the program counter went to house 1, then house 2, then house 20, then back to house 2, but then went back to house 20 a second time because it was the next house after 2 with any code. When it got there, it delivered the Pi again, but then was told to RETURN but didn’t know where to RETURN to! So it got confused and gave up.
We can solve this problem though by putting a REMark at line 21. It won’t actually do anything, but the program counter won’t get lost if we do."