CONTENTS | PREV | NEXT
6C. endproc/return
------------------
As stated before, ENDPROC marks the end of a function definition, and may
return a value. Optionally RETURN may be used at any point in the function
to exit, if used in main(), it will exit the program.
RETURN [<returnvalue>] /* optional */
Example:
PROC getresources()
/* ... */
IF error THEN RETURN FALSE /* something went wrong, so exit and fail */
/* ... */
ENDPROC TRUE /* we got this far, so return TRUE */
a very short version of a function definition is:
PROC <label> ( <arg> , ... ) IS <exp>
("RETURN" instead of "IS" is allowed, but obsolete)
These are function definitions that only make small computations, like
faculty functions and the like: (one-liners :-)
PROC fac(n) IS IF n=1 THEN 1 ELSE fac(n-1)*n