User Guide > Scripting > Script Statements > Return Statement
Was this helpful?
Return Statement
 
Description
The Return statement can be used for early termination of the processing of a script, function, or expression. It can be optionally used to return a value or a newly constructed object.
Syntax
Return expr
OR
Return NEW objectconstruction
OR
... Return
Arguments
expr - An optional expression whose value is returned. This expression can also be an object variable that was initialized within the function.
NEW objectconstruction - Used within a function that is declared to return an object type. This allows the function to immediately create and return a new object instance without first assigning it to a local variable.
Remarks
When used in an expression or a script, the Return statement works as if the end of the expression has been reached. Any value left on the stack becomes the return value. If a value is placed in the expr argument, then that value is explicitly returned.
When used in a Function procedure, the Return statement causes the immediate termination of the function. Execution resumes with the statement after the calling statement.
If a function's return value is an object type, the RETURN statement can return either:
An initialized object variable (Return foo).
A new object instance (Return NEW DJComponent "...").
Note:  Returned values from scripts executed in process expression steps are not retained upon script completion. Use variables, macros, external files, etc. to retain values that can be tested in other process steps. See also Decision Step.
Example
Terminating an expression with 25 as the Return value:
...
25
Return
Terminating an expression with 37 as the Return value:
...
Return 37
Exiting early from a script or function:
if counter > max then
return
end if

'more statements
Returning a newly constructed object:
FUNCTION GetNewIterator() AS DJComponent
 RETURN NEW DJComponent "XPath Iterator 1.1.1"
END FUNCTION
Returning an initialized object variable:
PUBLIC FUNCTION GetConfiguredObject(do_create) AS DJComponent
 DIM foo AS DJComponent
 SET foo = NOTHING ' Object variable must be initialized

 IF do_create THEN
  SET foo = NEW DJComponent "Configuration object"
  ' ... configure foo ...
 END IF

 RETURN foo ' Returns the object (either the new one or NOTHING)
END FUNCTION
 
Last modified date: 01/08/2026