Gosub Statement

Use the gosub statement to unconditionally jump to a local label — for more information, refer to Labels. The syntax of the gosub statement is:

gosub label_name
...
label_name:
...
return

This will transfer control to the location of a local label specified by label_name. Also, the calling point is remembered. Upon encountering the return statement, program execution will continue with the next statement (line) after gosub. The gosub line can come before or after the label.

It is not possible to jump into or out of routine by means of gosub. Never jump into a loop or other structured statement, since this can have unpredictable effects.

Note : Like with goto, the use of gosub statement is generally discouraged. mikroBasic PRO for ARM supports gosub only for the sake of backward compatibility. It is better to rely on functions and procedures, creating legible structured programs.

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code