The return command is used to terminate the execution of a function, and to optionally return a value. The syntax of the return command is:
return optional_expression
where
optional_expression is a value or expression to evaluate and return.
The following function returns the maximum of two values:
define function Max( a, b ) local integer MaximumValue if ( a > b ) then MaximumValue = a else MaximumValue = b endif return( MaximumValue ) enddefine
This function requires two arguments, and will return a single value using the RETURN command. Functions that return a value are not executed using the CALL statement, since the CALL statement will not allow use of the value returned by the function. However, functions that return a value can be used within any expression. For example, they can be used in print statements:
print Max( 3, 6)
Or they can be used in assignments:
m = Max( 3, 6)
Or they can be used in calls to other functions:
m = Max( Max( 3, 6 ), 1 )
In the last case, the function Max is called with two arguments, one of which is the expression Max(3, 6), which evaluates to 6. When the statement executes, the variable m will be assigned the value 6.
A function can have more than one return statement. The Max function could also be coded as:
define function Max( a, b ) if ( a > b ) return( a ) return( b ) enddefine
When the RETURN statement is used without an expression to return, it simply causes the function to terminate, just as if it reached the end of the function definition.
© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.