Note:
Pressing Ctrl and C will raise a HALT condition (discussed later) in the script. If the script CATCH's the HALT condition, then the script may not abort.Note: If using REXX GUI to create a graphical user interface, then CTRL-C does not raise the HALT condition, nor abort a REXX script. CTRL-C also does not work when running the script from Rexx Programmer Center, but you can use the "Run -> Halt script" menu item to raise the HALT condition and abort a script (even when running a script that uses REXX GUI).
EXIT keyword
A script can stop itself by executing the EXIT instruction, which consists simply of the EXIT keyword. As soon as REXX encounters an EXIT instruction, it ends the script, regardless of whether there are more instructions after the EXIT.
/* Terminate the script before the last line */ SAY "Here is some text" EXIT SAY "More text"Above, the script displays Here is some text, but the script ends before the second SAY instruction, and therefore More text never gets displayed.
An EXIT is implicitly understood to be at the bottom of a script. In other words, when REXX gets to the last line in a script, it automatically ends the script after that last instruction (unless that instruction causes a jump back to some earlier instruction in the script such as may be the case with the END or SIGNAL keywords). So, you don't need an EXIT instruction at the bottom of a script, although it's OK to put one there.
You can have more than one EXIT instruction in a script, if you need to end the script in various places.
Note: A RETURN keyword may be used instead of the EXIT keyword. The primary difference is that EXIT can abort a script regardless of where you are within your script, whereas RETURN will end the script only if you are not within some subroutine or function.
Returning a value
If you wish to return a value to the program that ran your script (or if your script was launched by another REXX script, and you wish to return a value to be stored in that other REXX script's 'RC' variable), then simply place that value after the EXIT keyword. Typically, you return a 0 if the script has no errors. Here, we return an "error number" of 30.
EXIT 30You can return a literal string if desired, for example here we return the string Some text:
EXIT "Some text"You can also specify a variable name, and its value is substituted, for example here we return the value of the variable 'MyVar':
MyVar = "Some text" EXIT MyVarSometimes, the program that runs your script may do something with the value you return. Check the documentation for the program you use to run your script, to see what sorts of values (if any) it understands/allows, and for what purpose it uses a value you return.
To discover whether whomever calls your script requires you to return a value, you can use PARSE SOURCE.
Note: Neither Reginald's Script Launcher, nor Rexx Programmer Center, require you to return any value, and will not do anything with any value you return.