Welcome to jBASE's new documentation site! Many answers to your questions can be found by searching the Knowledgebase or viewing the jBASE Documentation. We also have a Google Group for peer discussion about jBASE. If you are unable to find the information you are looking for, jBASE Support will be glad to assist in resolving your technical problems. Enjoy and please provide comments and feedback .

How can we help you?

ONGOTO

Description

The ON...GOSUB and ON...GOTO statements are used to transfer program execution to a label based upon a calculation, or a condition being met. They take the general form: 

ON expression GOTO label{, label...}

or

ON expression GOSUB label{, label...}

Where:

expression should evaluate to an integer numeric value. Labels should be defined somewhere in the current source file.

ON GOTO will transfer execution to the labeled source code line in the program.

ON GOSUB will transfer execution to the labeled subroutine within the source code.

Note: 

  • Use the value of expression as an index to the list of labels supplied. If the expression evaluates to 1 then the first label will be jumped to, 2 then the second label will be used and so on.
  • If the program was compiled when the emulation included the setting generic_pick = true, then no validations are performed on the index to see if it is valid. Therefore, if the index is out of range this instruction will take no action and report no error.
  • If the program was compiled for other emulations then the index will be range checked. If found that the index is less than 1, it is assumed to be 1 and a warning message is issued If the index is found to be too big, then the last label in the list will be used to transfer execution and a warning message issued.

An example of use may be as: 

PROMPT ":"
3 *
PRINT @(29,28): "HELLO, PLEASE ENTER 1 TO CONTINUE OR ANOTHER KEY TO EXIT":
INPUT VAL
IF NUM(VAL) THEN
    IF VAL = 1 THEN
        GOTO 3
    END
    ELSE
        STOP
    END
END


Go back to jBASE BASIC.

Was this article helpful?