リターン

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

Return 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)

備考

The space or tab after Return is optional if the expression is enclosed in parentheses, as in return(expression).

戻るべき呼び出し元がない場合、Returnは代わりにExitを行います。

関数から呼び出し元へ複数の値を返す方法は、「呼び出し元への値の返し方」で説明したとおり、さまざまな方法があります。

Functions, Exit, ExitApp

Reports the value returned by the function.

MsgBox returnTest() ; Shows 123

returnTest() {
    return 123
}

最初のReturnは、直前の条件が真であれば、後続の関数呼び出しがスキップされることを保証します。2番目のReturnは、このように関数の最後に使うと冗長です。

#z::  ; Win+Z
^#z::  ; Ctrl+Win+Z
{
    MsgBox "A Win+Z hotkey was pressed."
    if GetKeyState("Ctrl")
        return  ; Finish early, skipping the function call below.
    MyFunction()
}

MyFunction()
{
    Sleep 1000
    return  ; Redundant when used at the end of the function like this.
}