☜ | QUITM[UMPS] by Example | ☞ |
Introduced in the 1977 ANSI M[UMPS] language standard.
Write 1 Do SUB Write 2
...
SUB ;
; ... check processing conditions
If PROBLEMS Quit
; ... process data
Quit
In this example, the value 1 is written, then the subroutine is
invoked. The subroutine starts out checking whether all
conditions are met that are needed for it to function properly.
If not all conditions are met, the first Quit command is
executed, and control reverts back to the calling program, i.e.
the command Write 2 is executed.
Otherwise, the rest of the subroutine is executed, and the final
Quit command is processed eventually, after which control
reverts to the calling routine and the command Write
2 is executed.
Set S="" For Set
X=$Order(DATA(S))
Quit:S="" Do
. ; process one occurrence of DATA(S)
. Quit
In this example, the second Quit command is very much like
the Quit commands in the previous example, but the first
Quit command, the one on the same line as the For
command, is used to terminate a loop that would otherwise
continue forever.
Addition in the 1990 ANSI M[UMPS] language standard.
Set X=$$ADD(13,45)
...
Quit
;
ADD(P,Q) Quit P+Q
In the case of an extrinsic function call, the value to be
returned to the calling program is specified as the argument of
the Quit command that returns control back to that calling
program.
;...
Set X=$$A()
Quit
A() For Quit 1
Quit 2
This example will yield an error (M16) when the command
Quit 1 is encountered in the context of the
For loop.
;...
Set SPECIES="Fowl",GENDER="F"
Write $$SUB(SPECIES,GENDER)
Quit
;
SUB(SP,GN) If SP="Fowl" Do
. If GN="F" Quit "Hen"
. Else Quit "Cock"
Else Quit "Don’t know"
This example will cause an error (M16) at the command
Quit "Hen".
The indented block is not called as an extrinsic function, and
hence cannot return a value.
Set INCOME=250000,DEPENDENTS=3 Do TAX
Quit
;
TAX Set TAX=0 Do
. If INCOME>5000 Do
. . If DEPENDENTS>0 Quit
. . Set TAX=(INCOME–5000)*0.05
. If INCOME>50000 Do
. . If DEPENDENTS>2 Quit
. . Set TAX=TAX+(INCOME–50000)*0.1
. If INCOME>200000 Do
. . If DEPENDENTS>4 Quit
. . Set TAX=TAX+(INCOME–200000)*0.2
Write "TAX=",TAX
Quit
Because the number of dependents is 3 (more than 0 or 2), the
first two blocks (INCOME>5000 and
INCOME>50000) have no effect. The third block adds
(250000–200000*.02)=10000 to TAX (which still is 0), so
that the amount written will be 10000.
The Quit commands in the indented blocks with two dots at
the start of the line only terminate the ‘two dot’ level, and
return control to the ‘one dot’ level.
Addition in the 1995 ANSI M[UMPS] language standard.
Argument indirection is allowed to return a value from a
function:
Quit @ARGUMENT
For K=1:1:100 Quit:condition VALUE Do something
An occurrence of a Quit command with an argument
in the scope of a For command will cause an error
(M16).
Examples with naked references:
Quit VALUE
Set ^ABC(1,2)="reset naked indicator"
; naked indicator is now ^ABC(1,
Quit ^(3,4)
; naked indicator is now: ^ABC(1,3,
; Actual reference is: ^ABC(1,3,4)
Copyright © Standard Documents; 1977-2024 MUMPS Development Committee;
Copyright © Examples: 1995-2024 Ed de Moel;
Copyright © Annotations: 2003-2008 Jacquard Systems Research
Copyright © Annotations: 2008-2024 Ed de Moel.
The information in this page is
NOT authoritative and subject to be modified
at any moment.
Please consult the
appropriate (draft) language standard for an
authoritative definition.
Some specifications are "approved for inclusion in a future standard". Note that the MUMPS Development Committee cannot guarantee that such future standards will indeed be published.
This page most recently updated on 15-Nov-2023, 14:46:53.
For comments, contact Ed de Moel (demoel@jacquardsystems.com)