Documentation Comments
Use this form to comment on this topic. You can also provide any general observations about the Online Documentation, or request that additional information be added in a future release.
Reality V15.0 ()
RETURN Statement (DataBasic) (m618703+return_s.htm)
Returns to the calling program from a subroutine or external function.
RETURN {TO statementLabel}
RETURN(value)
TO statementLabel
Specifies a label that marks the statement to which control is to be transferred.
Refer to the section
Statement Labels.
value The value to be returned by an external function.
RETURN transfers control from a subroutine back to the statement immediately following the GOSUB or CALL statement that called it.
RETURN TO transfers control from the subroutine to the statement with the specified statementLabel. If the statement label does not exist, an error message is displayed at compile time.
GOSUB 15 PRINT "BACK FROM SUBROUTINE" . . 15 * SUBROUTINE XYZ . . RETURN
Control returns to the PRINT statement following the GOSUB that called the subroutine.
10 GOSUB 50 PRINT "SUBROUTINE EXECUTION COMPLETE" . . 50 * SUBROUTINE HERE . . IF ERROR RETURN TO 99 75 RETURN 99 PRINT "ERROR ENCOUNTERED HERE"; STOP
If an error occurs in the subroutine, control transfers to label 99, an error message is displayed and the program terminates. Otherwise, control is returned to the statement following the GOSUB that called the subroutine.
**************************************
* Subroutine DISTANCE
*
* Computes the distance between two points.
*
SUBROUTINE DISTANCE(X1, Y1, X2, Y2, D)
DX = X2 - X1
DY = Y2 - Y1
D = SQRT(DX * DX + DY * DY)
RETURN
END
**************************************
This example defines an external subroutine called DISTANCE that accepts five arguments and it computes the distance between two points (defined by the X1/Y1 and X2/Y2 parameters). On return, the result is in the D parameter.
**************************************
* Function DISTANCE
*
* Returns the distance between two points.
*
**************************************
FUNCTION DISTANCE(X1, Y1, X2, Y2)
DX = X2 - X1
DY = Y2 - Y1
RETURN(SQRT(DX * DX + DY * DY))
END
This does the same as the previous example, but is written as an external function that returns the result of the calculation.