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`.
Example
`
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
`
Differences from QB

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

See also

- `Select Case`
- `On...Gosub`
- `Goto`
- `Labels`