How do you jump to a label within a procedure?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Random Terrain
Posts: 63
Joined: Fri Jul 09, 2021 9:48 pm
Location: USA
Contact:

How do you jump to a label within a procedure?

Post by Random Terrain »

Since goto doesn't exist, how do you jump to a label?


Thanks.
User avatar
Paul
Posts: 195
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:

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

Post 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.
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

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

Post 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.
User avatar
Random Terrain
Posts: 63
Joined: Fri Jul 09, 2021 9:48 pm
Location: USA
Contact:

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

Post 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?
User avatar
Paul
Posts: 195
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:

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

Post 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
User avatar
Random Terrain
Posts: 63
Joined: Fri Jul 09, 2021 9:48 pm
Location: USA
Contact:

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

Post 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.
Post Reply