[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index]
[Date Index]
[Thread Index]
[SQR-USERS Info]
[SQRUG Home Page]
Re: Procedures
On Wed, Jul 12, 2000 at 04:06:17PM -0400, Derrick Fisher wrote:
> Is there any command you can use to leave a procedure before reaching
> the end-procedure command. For example say there are multiple IF
> statements in a procedure and as soon as an IF statement executes you
> want to exit the procedure so that no more IF statements will be
> processed. Is there some form of EXIT command in SQR you can use to do
> this ?
Actually, I think there are sort of two different questions here.
One is leaving a *procedure* "early". In other languages there is a
RETURN statement that causes a procedure to exit immediately. There's
no direct equivalent in SQR -- you have to fake it with GOTO or nested
IFs or whatever so that execution flows to the bottom of your procedure
and then passes back to the calling location in the usual way.
A second but related question is "how can I skip over some statements
and continue resume execution 'down the page a bit'". As other messages
have said, GOTO may be appropriate here in SQR (and if there were some
sort of "ELSEIF" we could avoid the need in many cases). The problem
with using BREAK for this purpose is that it's not really clear where to
jump to in this context -- how many IFs do you want to skip? However,
you can just use a dummy WHILE to get around this problem:
while 1 ! always enter loop; use BREAK to exit below
if #x=1
let #y=2
break
end-if
if #y=2
let #x=7
break
end-if
break ! make sure we exit loop no matter what
end-while
In this case, the while loop gives a context out of which the BREAK
should break.... (And, if this loop appears just before my
END-PROCEDURE, then the BREAKs will basically act like "RETURNs" would
have if they existed. :) )
Nathan
----------------------------------------------------------------------------
Nathan Stratton Treadway | Ray Ontko & Co. | Software consulting services
nathant@ontko.com | Richmond, IN | http://www.ontko.com/
- References:
- Procedures
- From: Derrick Fisher <DFisher@CO.NEW-CASTLE.DE.US>