Main Menu

Errors using Goto

Started by cwbraue, February 04, 2017, 03:26:39 PM

Previous topic - Next topic

cwbraue

I am new to playbasic, though I've used other basic languages. Every time I try to use the Goto command I get an error "label Goto is not defined". Goto is one of the simplest commands in Basic, so I don't understand why I can't get it to work. I am using line numbers with it, e.g. Goto 15, but it gives me the error and won't even run the program.

kevin

#1
    That won't work  as Line numbers don't exist in PlayBASIC, or the vast majority modern BASIC derivatives that I can think of.     So Goto or Gosub expects a LABEL name to jump to.   A Label is just named marker, that you can place where you want to goto or gosub into up/down the code.     There's a few stylistic limitations with labels, namely they must be left justified.   If it's not, it won't be seen as a label and you'll get an error.   This prevents some (not all) of the really ugly usages  some legacy coders seems set upon using..


PlayBASIC Code: [Select]
     Goto MyLabel10

print "This line is being skipped by the Goto above"


MyLabel10:


print "End of program"
Sync
waitkey





    See:  PlayBASIC Manual / PlayBASIC documentation