APPX is the Premier Development and Runtime Environment for Business Application Software
(Answer) (Category) FAQ's - APPX Software, Inc. : (Category) APPX Utility : (Category) APPX Development Environment : (Category) ILF (Integrated Language Facility) :
GOSUB/SUBR/COPY exit considerations.
If you need to exit early from your subroutine, you need to be careful about how it is called. You normally use an EXIT to return from a SUBR, a RETURN to exit from a GOSUB, and a GOTO/LABEL to exit from a COPY'd routine. Falling out the bottom (process an END statement) is the best method and will work in all cases, as will the GOTO/LABEL concept.

If you use an EXIT or RETURN statement in the subroutine, then you may be setting yourself up for a problem.

Exiting a subroutine with a RETURN for GOSUB calls will generate an EM Compiler error if you try to call it as a SUBR. A SUBR is a standalone process that now has a RETURN without a GOSUB.

A worse problem is using an EXIT in the subroutine. This works fine when you call it as a SUBR. It also does not complain when you call it as a GOSUB. The problem is that the GOSUB brings the code inline. This means that the EXIT statement in the subroutine will also exit the calling code. This can be handy if this is what you really intended to do. This can be bad if you forget and call it with a GOSUB intending on it to return back when the GOSUB is done.

Try not to include a RETURN or EXIT in an external subroutine. Since you can never be completely sure of how it will be called in the future.

[Append to This Answer]
2004-Mar-17 10:35am
Previous: (Answer) ILF verb shortcuts (abbreviations).
Next: (Answer) GOSUB/COPY/SUBR usage considerations?
This document is: http://board.appx.com/cgi-bin/fom.cgi?file=233
[Search] [Appearance]
This is a Faq-O-Matic 2.719.
Copyright 2003 by APPX Software, Inc. All rights reserved.