GOSUB


Language statement GOSUB


10
20  GOSUB label
30
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.


See examples


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 an article using the comments link below. Note, an offline language reference text file is now avialable – see the Download section.

Comments


' Note: using SUB instead of GOSUB is much more easy and modular.

x = 50
Gosub
routine1 ' prints 100
Print x ' prints 50
routine2 x ' prints -50
Print x ' prints 50

' Using GOSUB inside SUB:
Sub routine2(x)
Gosub routine3
Exit Sub

Label routine3
x = -x
Print x
Return
End
Sub

Pause
End
' End of program

' Using GOSUB with LOCAL variables:
Label routine1
Local x = 100
Print x
Return