Page 1 of 1

RETURN from FN or PROC

Posted: Fri 19 Apr 2019, 21:33
by MattC
Hi,

Which is the more appropriate to use?:

Code: Select all

A% = FNsubroutine(A%)
...
DEF FNsubroutine(a%)
= 10
or

Code: Select all

PROCsubroutine(A%)
...
DEF PROCsubroutine(RETURN a%)
a% = 10
ENDPROC
Both return the value to the original variable. Is there a usual or more correct one to use for this? I can see in some cases it would be more obvious depending on the circumstances, but not always.

Matt

Re: RETURN from FN or PROC

Posted: Sat 20 Apr 2019, 09:10
by DDRM
Hi Matt,

As you say, it depends on circumstances. I'd tend to use the FN approach if I only wanted one result, and the PROC approach if I wanted to return more than one. Using FN also means you can use it like a variable directly in an expression:

product = FNGetResultOne(inputs) * FNGetResultTwo(inputs2)

You'll see lots of examples of this in the manual.

Using a function means the result needs to be returned to a variable, which can (but doesn't have to be) a different one, while using RETURN and a procedure will always return it in the same variable (overwriting the old value) - either situation may be desirable, or not!

Hope that helps,

D

Re: RETURN from FN or PROC

Posted: Sat 20 Apr 2019, 15:09
by MattC
Thanks. It's good to get other opinions.

Matt