Rexx Tutorial on Rexx Variables

in rexx, all variables are bound with the ‘=’ statement. variable names are sometimes referred to as symbols. they may be composed of letters, digits, and characters such as ‘. ! ? _’. a variable name you create must not begin with a digit or a period. a simple variable name does not include a period. a variable name that includes a period is called a compound variable and represents an array or table.

the following are the basic types of variables in rexx which were also explained in the previous chapter −

  • integers − this is used to represent an integer or a float. an example for this is 10.

  • big integers − this represents a large integer value.

  • decimal − a decimal value is a string of numerics that contains a decimal point but no exponent identifier.

  • float − a float value is a string that represents a number in the scientific notation.

  • string − a series of characters defines a string in rexx.

different types of variable functions

in this section, we will discuss regarding the various functions a variable can perform.

variable declarations

the general syntax of defining a variable is shown as follows −

var-name = var-value 

where

  • var-name − this is the name of the variable.

  • var-value − this is the value bound to the variable.

the following program is an example of the variable declaration −

example

/* main program */ 
x = 40 
y = 50 
result = x + y 
say result

in the above example, we have 2 variables, one is x which is bound to the value 40 and the next is y which is bound to the value of 50. another variable called result is bound to the addition of x and y.

the output of the above program will be as follows −

90

naming variables

variable names are sometimes referred to as symbols. they may be composed of letters, digits, and characters such as ‘. ! ? _’ . a variable name you create must not begin with a digit or period.

if a variable has not yet been assigned a value, it is referred to as uninitialized. the value of an uninitialized variable is the name of the variable itself in uppercase letters.

an example of an unassigned variable is as follows −

example

/* main program */ 
unassignedvalue 
say unassignedvalue 

if you run the above program you will get the following output −

unassignedvalue
sh: unassignedvalue: command not found
     2 *-* unassignedvalue 
       >>>   "unassignedvalue"
       +++   "rc(127)"

variables can be assigned values more than once. the below program shows how the value of x can be assigned a value multiple times.

example

/* main program */ 
x = 40 
x = 50 
say x 

the output of the above program will be as follows −

50

printing variables

the values of variables are printed using the say command. following is an example of printing a variety number of variables.

example

/* main program */ 
x = 40 

/* display an integer */ 
say x 
y = 50.5 

/* display a float */ 
say y 
z = "hello" 

/* display a string */ 
say z 

the output of the above program will be as follows −

40 
50.5 
hello