UnderwareDESIGN

PlayBASIC => Beginners => Topic started by: cwbraue on February 04, 2017, 03:26:39 PM

Title: Errors using Goto
Post by: cwbraue on February 04, 2017, 03:26:39 PM
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.
Title: Re: Errors using Goto
Post by: kevin on February 04, 2017, 06:15:53 PM
    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..


[pbcode]

    Goto MyLabel10

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


MyLabel10:

   
    print "End of program"
    Sync
   waitkey
 
[/pbcode]


    See:  PlayBASIC Manual / PlayBASIC documentation (http://www.playbasic.com/help.php)