What is the function of GOSUB statement? short answer
Answers
Answer:
he GOSUB statement has two forms of execution: the direct branch to a specified subroutine, and the computed branch to one of several subroutines.
When the first form is used, program control is transferred to the line starting with the specified label. Once a RETURN statement is encountered, program control transfers back to the statement following the corresponding GOSUB in the main program. The set of statements confined between the branch label and the RETURN statement constitutes an internal subroutine.
The ON...GOSUB syntax variation, or computed GOSUB, may be used to call different subroutines according to the value of expr. expr is evaluated and truncated into an integer n, and the subroutine beginning with the nth label on the statement line is given control of the program. If expr evaluates to a number less than 1 or greater than the number of statement labels listed, no action is taken.
The colon is optional in the statement label reference. Furthermore, the statement label may be anywhere in the program; that is, it may either precede or follow the referencing GOSUB statement. If the specified statement label is not found, an error message is printed at compile time.