The ON-GoTo Statement

The ON-GoTo Statement

    This statement is a conditional branch transfer type of statement. The transfer of control depends on the value of the expression which is a part of this statement.
    The general form is
    on go
    where
    v -- may be a constant, a variable, or an expression
    n1, n2, …np – are labels of other statements in a program. The labels n1,
    n2, …np must be separated from each other by a comma.
    This statement functions as follows
    When v =1, control goes to statement labeled n1,
    When v =2, control goes to statement labeled n2,
    …………….
    …………..
    When v =p, control goes to statement labeled np.

    Program
    10 LET X=3
    20 ON X GOTO 80, 60, 30
    30 PRINT X
    40 X=X-1
    50 GOTO 20
    60 PRINT X
    70 GOTO 40
    80 PRINT X
    90 STOP
    100 END

    Output
    3
    2
    1

Last modified: Wednesday, 18 January 2012, 10:45 PM