How To

Goto stuff.

1

The14thdoctor 2020-04-24 11:33 (Edited)

I can get my program to go to a section if you do a specific input but another section if a different answer is typed (Kind of like a yes/no thing), but what does it mean by “variable not initialized”


Timo 2020-04-24 12:53 (Edited)

Before you can read a variable, it needs a value already.

PRINT V

...will give the error.

V=100
PRINT V

...will work.

Best practice is to initialize all global variables at the beginning of your program. It is also a good overview for all used global variables.


The14thdoctor 2020-04-24 13:05 (Edited)

Thanks. What do I do when I set the variable in an input?


Timo 2020-04-24 15:06

INPUT should work fine. If you have problems, post your code here and I will check it.


The14thdoctor 2020-04-24 15:14

PRINT "A)YES"
PRINT "B)NO"
INPUT ">";A$
PRINT
IF A$="A" THEN GOTO BUYSPAREPARTS ELSE IF A$="B" THEN GOTO OXEN

That is the section that is messing up.


Timo 2020-04-24 16:29

This part alone works fine, better show your complete program. you can attach it here.


was8bit 2020-04-24 16:43

This works....

PRINT "A)YES"
PRINT "B)NO"
INPUT ">";A$
PRINT
IF A$="A" THEN GOTO BUYSPAREPARTS ELSE IF A$="B" THEN GOTO OXEN


BUYSPAREPARTS:
CLS
PRINT "SPARE PARTS"

OXEN:
CLS
PRINT "OXEN"

Perhaps you dont have labels made or made correctly ?


The14thdoctor 2020-04-24 17:01

Thanks


was8bit 2020-04-24 17:27

Let us know if you get your code running ok :)


Log in to reply.