RETURN Statement |
RETURN
The MyBASIC2 command RETURN finishes a subroutine which is called with the statement GOSUB. After finishing the subroutine the program continues after the last GOSUB executed.
The RETURN statement can also be used to return from a FUNCTION or SUB. However, it is recommended that you use EXIT FUNCTION or EXIT SUB instead.
Examples:
' This script is an example of MyBASIC2 BEGIN: n = 10 DIM arr(10) AS REAL GOSUB CALC GOSUB SHOW END
CALC: arr(0) = 1 FOR i = 1 TO n - 1 IF i = 1 THEN arr(i) = 1 ELSE arr(i) = arr(i - 1) + arr(i - 2) NEXT RETURN
SHOW: FOR i = 0 TO n - 1 PRINT arr(i); ", " NEXT PRINT , RETURN
|