- Rexx Tutorial
- Rexx - Home
- Rexx - Overview
- Rexx - Environment
- Rexx - Installation
- Rexx - Installation of Plugin-Ins
- Rexx - Basic Syntax
- Rexx - Datatypes
- Rexx - Variables
- Rexx - Operators
- Rexx - Arrays
- Rexx - Loops
- Rexx - Decision Making
- Rexx - Numbers
- Rexx - Strings
- Rexx - Functions
- Rexx - Stacks
- Rexx - File I/O
- Rexx - Functions For Files
- Rexx - Subroutines
- Rexx - Built-In Functions
- Rexx - System Commands
- Rexx - XML
- Rexx - Regina
- Rexx - Parsing
- Rexx - Signals
- Rexx - Debugging
- Rexx - Error Handling
- Rexx - Object Oriented
- Rexx - Portability
- Rexx - Extended Functions
- Rexx - Instructions
- Rexx - Implementations
- Rexx - Netrexx
- Rexx - Brexx
- Rexx - Databases
- Handheld & Embedded
- Rexx - Performance
- Rexx - Best Programming Practices
- Rexx - Graphical User Interface
- Rexx - Reginald
- Rexx - Web Programming
- Rexx Useful Resources
- Rexx - Quick Guide
- Rexx - Useful Resources
- Rexx - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Rexx - Signals
In Rexx, the signal instruction is used generally for two purposes, which are −
One is to transfer control to another part of the program. This is normally like the go-to label which is used in other programming languages.
The other is to go to a specific trap label.
If the signal command is used in any of the following instruction commands, the pending control structures will automatically be deactivated.
if ... then ... else ...
do ... end
do i = 1 to n ... end [and similar do loops]
select when ... then ... ...etc. otherwise ... end
The general syntax of the signal statement is shown as follows −
signal labelName signal [ VALUE ] labelExpression
Let’s look at an example of how to use the signal statement.
/* Main program */ n = 100.45 if \ datatype( n, wholenumber ) then signal msg say 'This is a whole number' return 0 msg : say 'This is an incorrect number'
The output of the above program will be as shown below.
This is an incorrect number.
If you change the value of the variable n to a whole number as shown in the following program −
/* Main program */ n = 100 if \ datatype( n, wholenumber ) then signal msg say ' This is a whole number ' return 0 msg : say ' This is an incorrect number '
You will get the following output −
This is a whole number
One can also transfer to the value of the label as shown in the following program −
/* Main program */ n = 1 if \ datatype( n, wholenumber ) then signal msg if n < 1 | n > 3 then signal msg signal value n 3 : say 'This is the number 3' 2 : say ' This is the number 2' 1 : say ' This is the number 1' return n msg : say ' This is an incorrect number ' exit 99
The output of the above program will be shown as follows −
This is the number 1
Trap Label Transfer Activation / Deactivation
As we have mentioned earlier, the signal instruction can also be used to transfer control to a trap label.
The general syntax of the Trap label transfer is given as follows −
signal ON conditionName [ NAME Label ] signal OFF conditionName
conditionName − This is the condition for which the signal should be either be turned on or off.
Label − The optional label to which the program should be diverted to.
Let’s see an example of using a trap label transfer.
/* Main program */ signal on error signal on failure signal on syntax signal on novalue beep(1) signal off error signal off failure signal off syntax signal off novalue exit 0 error: failure: syntax: novalue: say 'An error has occured'
In the above example, we first turn the error signals on. We then add a statement which will result in an error. We then have the error trap label to display a custom error message.
The output of the above program will be as shown follows −
An error has occurred.