Except when a QUIT appears on a line after a FOR, the QUIT command terminates execution of the current GT.M invocation stack level initiated by a DO, XECUTE, extrinsic function or special variable, and return control to the next "lower" level. In this case, QUIT restores any values stacked at the current level by NEWs or by parameter passing. A QUIT command terminates any closest FOR command on the same line. Note that M overloads the QUIT command to terminate DO, FOR, XECUTE and extrinsics ($$) of which FOR is the most different.
The format of the QUIT command is:
Q[UIT][:tvexpr] [expr | *lname | *lvn]
The optional truth-valued expression immediately following the command is a command postconditional that controls whether or not GT.M executes the command.
When a QUIT terminates an extrinsic function, it must have an argument that supplies the value returned by the function; in all other cases, QUIT must not have an argument and must be followed by at least two (2) spaces to separate it from the next command on the line.
An indirection operator and an expression atom evaluating to a QUIT argument form a legal argument for a QUIT.
An unsubscripted lvn (lname) specifies the root of an array, while a subscripted lvn must specify an alias container.
When QUIT * terminates an extrinsic function or an extrinsic special variable, it always returns an alias container. If lvn is an lname that is not an alias, QUIT * creates an alias container. For more information and examples of alias variables, refer to “Alias Variables Extensions”.
The QUIT performs two similar, but different, functions depending on its context. Because FORs do not add levels to the GT.M invocation stack, QUITs inside FOR loops simply terminate the loop. QUITs that terminate DOs, XECUTEs and extrinsics remove a GT.M invocation stack level and therefore may adjust the local variable environment resulting from previous NEWs or parameter passing. A QUIT from an extrinsic or a frame created by an argumentless DO restores $TEST to its stacked value.
An indirection operator and an expression atom evaluating QUIT arguments forms a legal argument for a QUIT other than from a FOR.
Attempting to QUIT (implicitly or explicitly) from code invoked by a DO, XECUTE or extrinsic after that code issued a TSTART not yet matched by a TCOMMIT, produces an error.
Do A Quit A Write !,"This is label A"
The explicit QUIT at the line preceding the label A prevents line A from executing twice. The sub-routine at line A terminates with the implicit QUIT at the end of the routine.
Write $$ESV Quit ESV() QUIT "value of this Extrinsic Special Variable"
Because the label ESV has an argument list (which is empty), GT.M can only legally reach that label with an extrinsic invocation. The QUIT on the second line prevents execution from erroneously "falling through" to the line labeled ESV. Because ESV identifies a subroutine that implements an extrinsic special variable, the QUIT on the line after ESV has an argument to provide the value of the extrinsic.
Set x="" For Set x=$Order(^BAL(x)) Quit:x]]"AR5999"!'$Length(x) DO STF
The postconditional QUIT terminates the FOR loop. Note the two spaces after the QUIT because it has no argument.