Return

Returns from a function or subroutine to which execution had previously jumped via function-call, Gosub, Hotkey activation, GroupActivate, or other means.

Return , Expression

Parameters

Expression

This parameter can only be used within a function.

If omitted, it defaults to an empty string.

Since this parameter is an expression, all of the following lines are valid:

return 3
return "literal string"
return MyVar 
return i + 1
return true  ; Returns the number 1 to mean "true".
return ItemCount < MaxItems  ; Returns a true or false value.
return FindColor(TargetColor)

Known limitation: For backward compatibility and ease-of-use, the following two lines are functionally identical:

return MyVar
return %MyVar%

In other words, a single variable enclosed in percent signs is treated as a non-expression. To work around this, make it unambiguously an expression by enclosing it in parentheses; for example: return (%MyVar%).

Remarks

If there is no caller to which to return, Return will do an Exit instead.

There are various ways to return multiple values from function to caller described within Returning Values to Caller.

Functions, Gosub, Exit, ExitApp, GroupActivate

Examples

The first Return separates the hotkey from the subroutine below. If it were not present, pressing the hotkey would cause Sleep 1000 to be executed twice.

#z::
MsgBox The Win-Z hotkey was pressed.
Gosub MySubroutine
return

MySubroutine:
Sleep 1000
return

Reports the value returned by the function.

MsgBox % returnTest() ; Shows 123

returnTest() {
    return 123
}