Skip to content

GOSUB


Control flow statement to use a section of code and return.

Syntax

` Gosub label

`

Description

Execution jumps to a subroutine marked by a line label. Always use Return to exit a Gosub, execution will continue on next statement after Gosub.

The line label where Gosub jumps must be in the same main/function/sub block as Gosub. All the variables in the subroutine are shared with the block, no arguments can be used. For this reason Gosub is considered bad programming practice as it can generate unreadable and untraceable code. It is better to use Sub or Function instead.

Examples

start GeSHi

vb
'' Compile with -lang qb

'$lang: "qb"

GoSub message
End

message:
Print "Welcome!"
Return

end GeSHi

Dialect Differences

Differences from QB

See also

  • Goto
  • Return (from Gosub)
  • Sub
  • Function
  • Option Gosub
  • Labels

Back to DocToc

Translated from FreeBASIC official docs. Contact us for removal if infringed.
FreeBASIC is an open-source project, not affiliated with Microsoft