Skip to main content

Return and Quit Commands

The DoubleByVal class method uses Return. This command terminates execution of a class method or routine. You can place Return in several places, so that different conditions cause termination at different points. There is also a Quit command that does the same thing. You can use either command with an argument to return a value from the class method.

Even though the two commands are similar, a suggested convention for using these two commands is:

  • Use Quit without an argument to terminate execution of code.

  • Use Return with an argument to terminate execution of code and return a value.

ObjectScript.RightTriangle uses this convention. There are important differences between Return and Quit, covered later when discussing looping constructs, such as For.

VS Code - ObjectScript

/// examples for ObjectScript Tutorial
Class ObjectScript.Examples
{

ClassMethod DoubleByVal(anynumber as %Numeric) as %Numeric
{
    return anynumber * 2
}
}

Quit also has a use outside of a class method or routine. While you're writing code, VS Code - ObjectScript will alert you to syntax errors as you type. But runtime errors, such as an undefined variable, will terminate the execution of your code. You will see the error message, along with the line (label name plus any offset) containing the error, in the Terminal window. In addition, the USER> prompt will change to something like this: USER 2d0>. Just enter Q or Quit to return the prompt to its normal state.

VS Code - ObjectScript

/// examples for ObjectScript Tutorial
Class ObjectScript.Examples
{

/// demo of <UNDEFINED> error
ClassMethod BadMethod()
{
    set a = 1
    set b = 2
    write c
}
}
Testing using the Terminal


USER>do ##class(ObjectScript.Examples).BadMethod()

    write c }
    ^
<UNDEFINED>zBadMethod+3^ObjectScript.Examples.1 *c
USER 2do>quit

USER>
Feedback