On GoTo Command

Purpose

Performs a branch to a local label specified after GoSub, depending on the value of the expression after On.

Syntax

On n GoTo label1, label2, …

n:integer expression
label1,label2, …:label names

Description

A branch to a local subroutine starting with a label is performed, depending on the value of n. If the value of n is less than 1 or greater than the number of labels specified after GoSub, no branch will be invoked. If n is not an integer, a Trunc(n) will be performed first and, if needed, a branch will then be taken. After a local subroutine invoked using On...GoTo is executed the program continues with the first statement after On...GoTo. If a local subroutine is not invoked, the execution immediately continues with the first statement after On...GoTo.

Example

OpenW 1

Local a%, n%

n% = 3

On n% GoTo p1, p2, p3, p4, p5, p6

p1:

Print "Mark p1:"

GoTo p7 :

p2:

Print "Mark p2:"

GoTo p7 :

p3:

Print "Mark p3:"

GoTo p7 :

p4:

Print "Mark p4:"

GoTo p7 :

p5:

Print "Mark p5:"

GoTo p7 :

p6:

Print "Mark p6:"

p7:

End

Remarks

See Also

On GoSub, On Call, GoTo, If, Select

{Created by Sjouke Hamstra; Last updated: 20/10/2014 by James Gaite}