User Login
Name
Password
Site Contents
News
About
Download
Scripts
Tutorials
Register
Support
FAQ
Script Reference
New User


Contact Me
Xide
Online Scripting Reference

gosub

Purpose
Temporarily jumps to a block of code (or subroutine) with the ability to return to where it came from.

Syntax
gosub {label}

{label}: A label within the script to temporarily jump to.



Notes
This command works the same way as a "goto" command, although it has the ability to be sent back to where it came from through the use of a "return" command.

It is good practice to always make sure that you match every "gosub" with a "return". Otherwise, you could get a large build-up of subroutine calls that will eventually cause a stack overflow.

Example
# gosub/return demo:

echo "This is a gosub/return demo.  I'm going to branch to a subroutine."
gosub :subroutine
echo "I've just returned from my subroutine"
halt

:subroutine
echo "I'm in my subroutine"
return



Return to item listing