- Rexx - Web Programming
- Rexx - Reginald
- Rexx - Graphical User Interface
- Rexx - Best Programming Practices
- Rexx - Performance
- Handheld & Embedded
- Rexx - Databases
- Rexx - Brexx
- Rexx - Netrexx
- Rexx - Implementations
- Rexx - Instructions
- Rexx - Extended Functions
- Rexx - Portability
- Rexx - Object Oriented
- Rexx - Error Handling
- Rexx - Debugging
- Rexx - Signals
- Rexx - Parsing
- Rexx - Regina
- Rexx - XML
- Rexx - System Commands
- Rexx - Built-In Functions
- Rexx - Subroutines
- Rexx - Functions For Files
- Rexx - File I/O
- Rexx - Stacks
- Rexx - Functions
- Rexx - Strings
- Rexx - Numbers
- Rexx - Decision Making
- Rexx - Loops
- Rexx - Arrays
- Rexx - Operators
- Rexx - Variables
- Rexx - Datatypes
- Rexx - Basic Syntax
- Rexx - Installation of Plugin-Ins
- Rexx - Installation
- Rexx - Environment
- Rexx - Overview
- Rexx - Home
Rexx Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
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 pke 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 −
Syntax
signal labelName signal [ VALUE ] labelExpression
Let’s look at an example of how to use the signal statement.
Example
/* 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.
Output
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 earper, 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 −
Syntax
signal ON conditionName [ NAME Label ] signal OFF conditionName
Where,
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 spanerted to.
Let’s see an example of using a trap label transfer.
Example
/* 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.Advertisements