bas7advr.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
ON...GOSUB and ON...GOTO Statement Details
  Syntax  Details  Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
ON...GOSUB and ON...GOTO branch to one of several specified lines,
depending on the value of an expression.
 
ON expression% GOSUB line-label-list
ON expression% GOTO line-label-list
    ■ The argument expression% is any numeric expression between
      0 and 255, inclusive.
    ■ The line-label-list consists of a list of line numbers or line
      labels, separated by commas. The value of expression% determines which
      line the program branches to. For example, if the value is 3,
      the third line specified in the list is the destination of the branch.
    ■ The value of expression% should be greater than or equal to 1 and less
      than or equal to the number of items in the list. If the value falls
      outside this range, one of the following results occurs:
 
        Value                          Result
        ═════════════════════════════  ══════════════════════════════════
        Number equal to 0 or greater   Control drops to the next BASIC
        than number of items in list   statement.
 
        Negative number or             BASIC generates the error message,
        number greater than 255        "Illegal function call."
 
Usage Notes
    ■ You can mix line numbers and labels in the same list.
    ■ ON...GOTO statement accepts a maximum of 60 line labels or line
      numbers. The SELECT CASE statement provides a more powerful,
      convenient, and flexible way to do multiple branches.