Return Statement

Moves execution back to the code that called a procedure.

Syntax

Non-function construct

Return

Function construct

Return expression

Parts

expression
For a function construct, mandatory value to return to the caller.

Instructions

In procedures of the types Sub and Set (Property), Return is the same as Exit Sub or Exit Property. You must not supply expression.

In procedures of the types Function and Get (Property), Return must include expression. The data type of expression must be compatible with the return type of the procedure. As an alternative, you can assign expression to the name of the procedure, then use Exit Function or Exit Property.

If you put Return in a block of the types Try or Catch that also includes a block Finally, Return causes Finally to execute. And if Return includes expression, it gets calculated after End Try. Return is not permitted in blocks of the type Finally.

Examples

Method RelativeTime(sec As Int32) As String
    If sec < 2*60 Return "seconds"
    If sec < 2*60*60 Return "minutes"
    If sec < 2*24*60*60 Return "hours"
    If sec < 2*7*24*60*60 Return "days"
    If sec < 2*30*24*60*60 Return "weeks"
    If sec < 2*365*24*60*60 Return "months"
    Return "years"
End Method

See also