LoginLogin
Might make SBS readonly: thread

GOTO???

Root / FAQs / [.]

JINC_DEVCreated:
Can someone please explain what GOTO does, with small simple words and possibly giving an example???

GOTO sends you to a specified label Example:
@LOOP

GOTO @LOOP

GOTO sends you to a specified label Example:
@LOOP

GOTO @LOOP
^ it helps when you have sections of code were you switch them around but have
def
/
end
between the main loops for sections and you can say
acls
while 1'main loop
'awesome code goes here
if clear==1 then GOTO@sect2
wend
def 'variable name
'user defined instructions
end
@sect2
while 1'main loop for second section
'awesome code goes here with different attributes for second section
wend

GOTO sends you to a specified label Example:
@LOOP

GOTO @LOOP
So does it skip to a certain line of code???

GOTO sends you to a specified label Example:
@LOOP

GOTO @LOOP
So does it skip to a certain line of code???
If you do
GOTO @EXAMPLE
'Your code

@EXAMPLE
Then it does. Sorry I couldn't give a more detailed explanation, others should be able to give more help.

GOTO sends you to a specified label Example:
@LOOP

GOTO @LOOP
So does it skip to a certain line of code???
If you do
GOTO @EXAMPLE
'Your code

@EXAMPLE
Then it does. Sorry I couldn't give a more detailed explanation, others should be able to give more help.
That Otay.

Protip: Don't ever use labels for loops. Use WHILE/WEND or REPEAT/UNTIL, to name a few.

Protip: Don't ever use labels for loops. Use WHILE/WEND or REPEAT/UNTIL, to name a few.
yep because you can use break on those but im not so sure on @loop. if you want to use @ then its good to use gosub.

Also you have to name e v e r y label, while using WHILE UNTIL lets you have clearer and more to-the-point code.

Also you have to name e v e r y label, while using WHILE UNTIL lets you have clearer and more to-the-point code.
you mean wend instead of until until is with repeat

Also you have to name e v e r y label, while using WHILE UNTIL lets you have clearer and more to-the-point code.
you mean wend instead of until until is with repeat
Nah, I just meant both WHILE WEND and REPEAT UNTIL. Should have at least put an "and" there...

Also you have to name e v e r y label, while using WHILE UNTIL lets you have clearer and more to-the-point code.
you mean wend instead of until until is with repeat
Nah, I just meant both WHILE WEND and REPEAT UNTIL. Should have at least put an "and" there...
oh. ok

GOTO works with these neat little things called ‘labels’ these labels essentially are words (letters and numbers without spaces) that start with the symbol ‘@‘ it should look something like this:
@Label ‘Doesn’t have to be the word label, it can be any word you want.
Basically let’s say you have some code under that label:
@Label
PRINT “HELLO WORLD”
So you are at the part of your code where everything is confusing and you need to know your way around, and you want your program to read a certain part of your code. Then you use the GOTO command, like this:
@Label
PRINT “HELLO WORLD”
GOTO @Label
Basically what is happening above is you specify your label (Which is @Label) then you are printing the words “HELLO WORLD” to the console, and then you are telling the code to reread the line where it says @Label. This is honestly the simplest way I can put it, it’s probably easier if you get better examples rather than mine.. Just think of it this way, when a program runs, there it reads line by line, I’ll call this a “pointer.” And a label is like a checkpoint, it saves the position of a pointer, and when you are using a GOTO command, it moves your pointer all the way up to that checkpoint (represented as the label).

GOTO works with these neat little things called ‘labels’ these labels essentially are words (letters and numbers without spaces) that start with the symbol ‘@‘ it should look something like this:
@Label ‘Doesn’t have to be the word label, it can be any word you want.
Basically let’s say you have some code under that label:
@Label
PRINT “HELLO WORLD”
So you are at the part of your code where everything is confusing and you need to know your way around, and you want your program to read a certain part of your code. Then you use the GOTO command, like this:
@Label
PRINT “HELLO WORLD”
GOTO @Label
Basically what is happening above is you specify your label (Which is @Label) then you are printing the words “HELLO WORLD” to the console, and then you are telling the code to reread the line where it says @Label. This is honestly the simplest way I can put it, it’s probably easier if you get better examples rather than mine.. Just think of it this way, when a program runs, there it reads line by line, I’ll call this a “pointer.” And a label is like a checkpoint, it saves the position of a pointer, and when you are using a GOTO command, it moves your pointer all the way up to that checkpoint (represented as the label).
You can also use labels to skip over lines of code.
GOTO @SKIP
BGMPLAY 0
@SKIP
Also, if you want an infinite loop, use a WHILE WEND loop. They're so much better.
T$="Hello world!"

WHILE 1
 VSYNC
 GCLS
 FOR I%=0 TO LEN(T$)-1
  GPUTCHR I%*16,104+FLOOR(32*SIN(2*PI()*((MAINCNT+I%)/90)))
 NEXT I%
WEND