RETURN
The RETURN
instruction gives the control of execution back to the
caller, optionally returning values on the stack.
Syntax
RETURN [
value [
,...]
]
- value can be any valid expression, an object reference or complex type reference such as a dynamic array reference.
Usage
The RETURN
instruction transfers the control back from a function with optional return values.
Record members can be returned with the
.*
or THRU
notation. Each member is returned as an independent
variable.
Consider using the fully typed function
definition syntax, with a RETURNS
clause in the function header, to get better
compilation control of your code. When using the RETURNS
clause, the compiler will
check that the function body contains RETURN
instructions that match the number of
return values as specified in the function definition.
A
function may have several RETURN
points (not recommended
in structured programming) but they must all return the same
number of values.
The number of returned values must correspond to the number of variables listed in the RETURNING
clause of
the CALL
statement invoking this function.
A function cannot return a static array, but can return the reference of a dynamic array or dictionary.
Example
MAIN
DEFINE fname, lname VARCHAR(30)
LET lname = lastname(943)
DISPLAY lnMAIN
DEFINE fname, lname VARCHAR(30)
LET lname = lastname(943)
DISPLAY lname
CALL fullname(235) RETURNING fname, lname
DISPLAY fname, lname
END MAIN
FUNCTION lastname(id INTEGER) RETURNS STRING
CASE id
WHEN 943
RETURN "McTiger"
OTHERWISE
RETURN NULL
END CASE
END FUNCTION
FUNCTION fullname(id INTEGER) RETURNS(STRING, STRING)
CASE id
WHEN 235
RETURN "Lee", "Park"
OTHERWISE
RETURN NULL, NULL
END CASE
END FUNCTION