Skip to content
Paul Squires edited this page Oct 14, 2026 · 2 revisions

Home › Control Flow Statements › GoSub

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.

Remarks

Dialect Differences

Differences from QB

See also

Examples

'' Compile with -lang qb

'$lang: "qb"

GoSub message

End

message:

Print "Welcome!"

Return

Category: Control Flow Statements
Kind: keyword


Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.

Clone this wiki locally