GOSUB and RETURN (Command)

and  are commands which allow use of subroutines in Petit Computer BASIC.

must be followed by a line number or a label. The point in the program where the  was encountered is pushed onto a 'call stack'. Execution of the program continues from that part of the program pointed to by the label or line number. Execution then continues as normal, until a  is encountered. When this happens, the last value added to the 'call stack' is removed, and execution continues from that point again.

Essentially, the idea is that you can create a small program, put a label at the beginning of it, and put  at the end of it. You can execute this small program in the middle of the main code by using  with that label. If you have a task that needs to be performed many times, this can save a lot of typing and make your code more robust to change. Even if a section of code is used only once, using subroutines to seperate different tasks can help make your program tidy and more easily understood and maintained.

The 'call stack' has a maximum depth of 255. This means that you can have 255 consecutive s, but the next one will generate an   error. If the system encounters a  when the call stack is empty, it generates a   error. is not allowed at the interactive command-line, this generates a.