Skip to content

On Goto

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

Home › Control Flow Statements › On...Goto

On...Goto

Jumps to a label based on an expression.

Syntax

On expression Goto label1[, ...]

Description

Branches to different labels depending on the value of expression. An expression value of 1 will branch to the first label, a value of 2 to the second, etc. If the value of expression is zero (0) or greater than the number of items in the list, execution continues on the next statement following the On...Goto.

It is recommended that the structured Select Case conditional statement be used instead of On...Goto.

Remarks

Differences from QB

  • FreeBASIC does not generate a run-time error if expression is negative or greater than 255.

See also

Examples

Dim choice As Integer

Input "Enter a number: ", choice

On choice Goto labela, labelb, labelc

labela:

Print "choice a"

End

labelb:

Print "choice b"

End

labelc:

Print "choice c"

End

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