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.
省略したときは、空文字列が初期値になります。
このパラメーターはexpressionなので、以下の行はすべて有効です:
return 3 return "literal string" return MyVar return i + 1 return true ; "true"を意味する数値1を返します。 return ItemCount < MaxItems ; trueまたはfalseを返します。 return FindColor(TargetColor)
return(expression)のように式が括弧で囲まれている場合、Returnの後のスペースやタブは省略できます。
戻るべき呼び出し元がない場合、Returnは代わりにExitを行います。
関数から呼び出し元へ複数の値を返す方法は、「呼び出し元への値の返し方」で説明したとおり、さまざまな方法があります。
Reports the value returned by the function.
MsgBox returnTest() ; 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.
}