GOSUB

GOSUB label

Causes program execution to branch to the specified label; when the RETURN command is encountered, execution branches to the command immediately following the most recent GOSUB command.

GOSUB should be used with caution. Using subroutines is more versatile and much easier to read.

See ON for ON n GOSUB Label1 for branching depending on a number n.

Example 1: Using GOSUB

while(ii < 20)
  gosub Inc
wend

end ' ends the program
  
label Inc
ii++
print ii
return

Example 2: Same as example 1, but using a subroutine instead of GOSUB

while(ii < 20)
  Inc()
wend
  
sub Inc()
  ii++
  print ii
end
Language
If there is insufficient information on this page and you wish learn more about GOSUB, please send an email to smallbasic@gmail.com. You can help to improve information about GOSUB by submitting a pull request, click View Source for details. Note, an offline language reference text file is also available - see the Download section.