Language basics / Flow control |
The RETURN instruction returns flow control to the function caller.
RETURN [ value [,...] ]
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.
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.
MAIN DEFINE fname, lname VARCHAR(30) CALL foo(NULL) RETURNING fname, lname DISPLAY fname CLIPPED, " ", UPSHIFT(lname) CLIPPED CALL foo(1) RETURNING forname, surname DISPLAY fname CLIPPED, " ", UPSHIFT(lname) CLIPPED END MAIN FUNCTION foo(code) DEFINE code INTEGER DEFINE person RECORD fname VARCHAR(30), lname VARCHAR(30) END RECORD IF code IS NULL THEN RETURN NULL, NULL ELSE LET person.fname = "John" LET person.lname = "Smith" RETURN person.* END IF END FUNCTION