Exit

Exits the current thread or (if the script is not persistent) the entire script.

Exit , ExitCode

Parameters

ExitCode

An integer between -2147483648 and 2147483647 (can be an expression) that is returned to its caller when the script exits. This code is accessible to any program that spawned the script, such as another script (via RunWait) or a batch (.bat) file. If omitted, ExitCode defaults to zero. Zero is traditionally used to indicate success.

Remarks

If the script is not persistent, Exit will attempt to terminate the entire script as though ExitApp was called.

If the script is not terminated, the Exit command terminates the current thread. In other words, the stack of subroutines called directly or indirectly by a menu, timer, or hotkey subroutine will all be returned from as though a Return were immediately encountered in each. If used directly inside such a subroutine -- rather than in one of the subroutines called indirectly by it -- Exit is equivalent to Return.

Use ExitApp to completely terminate a script that is persistent.

ExitApp, OnExit(), OnExit, Functions, Gosub, Return, Threads, #Persistent

Examples

In this example, the Exit command terminates the Sub2 subroutine as well as the calling subroutine.

#z::
Gosub, Sub2
MsgBox, This MsgBox will never happen because of the EXIT.
return

Sub2:
Exit  ; Terminate this subroutine as well as the calling subroutine.