Development Topics > BASIC Extensions > A-Shell Extensions > User-defined Functions
Exit Label $EXIT

Updated and reviewed July 2011

Besides exiting by hitting the ENDFUNCTION statement naturally, you may also exit from anywhere inside the function by executing the EXITFUNCTION statement. Note that "END FUNCTION" is equivalent to "ENDFUNCTION." 

As of 5.1.1192.0, the compiler recognizes a special label $EXIT: which may be placed near the end of a function (or procedure) in order to execute program statements after executing an EXITFUNCTION (or EXITPROCEDURE) statement but before actually exiting the function.

PROCEDURE TEST()

 

    DIMX A(100),S,50

    ...

    IF <some condition) EXITPROCEDURE

    ...

    ...

$EXIT:

    REDIMX A(0)   ! release the memory used by A()

 

ENDPROCEDURE

 

Note that while the $EXIT label is not case sensitive, you must include the $, lest it become an ordinary label which would be ignored by the EXITPROCEDURE statement. Also note that you must not include any EXITPROCEDURE/EXITFUNCTION statements in between the $EXIT and the ENDPROCEDURE/ENDFUNCTION, lest you create an infinite loop.

Also note that RESUME ENDPROCEDURE (or RESUME ENDFUNCTION) also executes the code following the $EXIT label, exactly as in the case of the EXITPROCEDURE / EXITFUNCTION statements. But care should be taken there to make sure no further error occurs before actually exiting, as it would likely lead to an infinite loop (returning to the error trap which then resumed to the $EXIT label...).   

History

2010 September, A-Shell build 1192: Feature added to A-Shell