ON ... GOSUB, ON ... GOTO, ON ... CALL statement
Purpose: These are control flow statements that will branch to a line label or subroutine depending on the value of a number.
Syntax 1: ON Number GOSUB ListSyntax 2: ON Number GOTO ListSyntax 3: ON Number CALL List Parameters:
|
Here is a complete example.
GLOBAL i INPUT "Enter a number(1,2,3) " , i ON i CALL Sub_one, Sub_two, Sub_three ON i GOSUB One, Two, Three ON i GOTO Label_One, Label_Two, Label_Three END ' To stop the program from flowing to the code below Label_One: PRINT "Label One" END Label_Two: PRINT "Label Two" END Label_Three: PRINT "Label Three" END One: PRINT "Subroutine One" RETURN Two: PRINT "Subroutine Two" RETURN Three: PRINT "Subroutine Three" RETURN SUB Sub_one PRINT "SUB One" END SUB SUB Sub_two PRINT "SUB Two" END SUB SUB Sub_three PRINT "SUB Three" END SUB
BCX Console Sample Programs using ON ... GOSUB, ON ... GOTO, ON ... CALL function.