spotlessmind1975 / ugbasic

An isomorphic BASIC language compiler for retrocomputers
Apache License 2.0
92 stars 16 forks source link

ON...GOTO (CPC) #1025

Closed poppichicken closed 9 hours ago

poppichicken commented 9 hours ago

hi Marco.

My apologies if I am misunderstanding. I don't want to waste your time needlessly.

BITMAP ENABLE(160,200,16)
BORDER WHITE
CLS BLACK
DEFINE KEYBOARD ASYNC

DIM x AS BYTE
x=30

ON x GOTO 10,20,30

10 PRINT 10:END
20 PRINT 20:END
30 PRINT 30:END

I'm expecting it to print 30, but it does the following:

image

poppichicken commented 9 hours ago

By the way, CGOTO works as expected.

DIM x AS BYTE
x=30

CGOTO x

10 PRINT 10:END
20 PRINT 20:END
30 PRINT 30:END

image

That's a very cool command!

spotlessmind1975 commented 9 hours ago

Hi @poppichicken and thank you for your kind bug report!

I'm expecting it to print 30, but it does the following:

The behavior is correct, because you asked to jump to the 30th option, which is not present. So the execution continues, printing the first entry. If you want it to print 30, you would use x = 3. I will add more examples on the manual, to better clarify the behavior.

Thank you again!

poppichicken commented 9 hours ago

Ah yes, I thought I was indeed misunderstanding. In fact I now remember reading something similar earlier in the manual.