Page 1 of 1

How do you jump to a label within a procedure?

Posted: Fri Jul 23, 2021 3:26 pm
by Random Terrain
Since goto doesn't exist, how do you jump to a label?


Thanks.

Re: How do you jump to a label within a procedure?

Posted: Fri Jul 23, 2021 3:44 pm
by Paul
Use "If/Else/Endif", "Repeat/Until", "Select/Case/EndSelect", etc...

If you post some code of what you have so far or are trying to accomplish it would be easier to show how to code it properly.

Re: How do you jump to a label within a procedure?

Posted: Fri Jul 23, 2021 3:46 pm
by Peter
Goto and Gosub no longer exist for a good reason. The code becomes very unreadable (spaghetti code).
I believe that you can change your code so that you no longer need Goto & Co.

Re: How do you jump to a label within a procedure?

Posted: Fri Jul 23, 2021 4:11 pm
by Random Terrain
Peter wrote: Fri Jul 23, 2021 3:46 pm Goto and Gosub no longer exist for a good reason. The code becomes very unreadable (spaghetti code).
I believe that you can change your code so that you no longer need Goto & Co.
Thanks. So instead of jumping over a section of code if something specific happens, I need to stick that section of code inside of an If-EndIf or a Select-EndSelect?

Does that sound right?

Speaking of labels, the page that mentions labels doesn't seem to have an example. If labels can't be jumped to, why do labels exist in SpiderBasic?

Re: How do you jump to a label within a procedure?

Posted: Fri Jul 23, 2021 4:53 pm
by Paul
Random Terrain wrote: Fri Jul 23, 2021 4:11 pm Speaking of labels, the page that mentions labels doesn't seem to have an example. If labels can't be jumped to, why do labels exist in SpiderBasic?
Labels are useful in DataSections (without a label you can't tell it what section of data to use)

Example...

Code: Select all

Restore last
For x=1 To 3
  Read a
  Debug a
Next


DataSection
  first:
  Data.i 1,2,3
  last:
  Data.i 7,8,9
EndDataSection

Re: How do you jump to a label within a procedure?

Posted: Fri Jul 23, 2021 5:48 pm
by Random Terrain
Paul wrote: Fri Jul 23, 2021 4:53 pm Labels are useful in DataSections (without a label you can't tell it what section of data to use)
OK, thanks.