Description

There are four ways to assign values to a variable: general, addition, subtraction, and concatenation. See the table for a description of each.

OperatorDescription
= (equal)Assigns a value to a variable.
+= (plus equal)Adds a value to the value already assigned to a variable.
-= (minus equal)Subtracts a value from the value already assigned to a variable.
 := (colon equal)Concatenates a value to a variable, after the value has already been assigned.

Syntax

variable = | += | -= | := expression

- OR -

matrix(subscript) = | += | -= | := expression

Remarks

The special assignmeThe special assignment operators have the following parameters.

ParameterDescription
variableA character or character string identifier that always appears on the left side of the assignment operator. The expression that defines its value must be on the right side of the operator.
expressionThe value of expression becomes the current value of the variable identifier. This parameter may be any constant or a calculation from a simple or complex expression.
matrixThe name of the matrix. When combined with an element subscript to identify a specific element, it performs the same function as variable.
subscriptSpecifies the element in the matrix that will be the target of the assignment statement. Together with a matrix name, it functions as variable.

Using a general assignment statement ( = ), assign a variable, before using any special assignment operator.

The matrix name and the element subscript specify a location within the matrix. Together, they function as a variable identifier. When the location is receiving an assignment, it must appear on the left side of the assignment operator. For example:

PRICE(75) = R/Q

The 75th element in the one-dimensional matrix PRICE is assigned the current value of R that has been divided by the current value of Q. In the following example:

CUST(2,3) = "E.T.BARENT"

the value of the literal string "E.T.BARENT" is assigned to the element in the second row, third column of the matrix CUST.

Special assignment operators ( +=, -=, := ) are used to change the value of a variable. They may not be used with dynamic arrays. No space is allowed between the two signs that make up each special assignment operator.

The form for addition assignment is:

variable += expression

This statement is equivalent to:

variable = variable + expression

The form for subtraction assignment is:

variable -= expression

The form for concatenation assignment is:

variable := expression

Note: The value of a variable is changed only after the expression has been evaluated.

Length

Number of characters to replace, beginning from start.

Each space and character within the string is counted as a character position. Also, note that the value specified for length includes the character position specified by start.

Example

Replaces the substring in variable that has been defined by the parameters start and length. If expression yields a string that is longer than the specified substring, the total string length of variable will increase. If expression yields a shorter string, then the total string length of variable decreases.

In other words, the entire substring defined by start and length is replaced by whatever is the value of expression.

* Assigns 9 to variable identifier Z.
Z = 9
* Decrement the value of A by one.
A = A - 1
* Assigns the value "W.H. STEVENS" to N.
N = "W.H. STEVENS"
* The variable identifier ANS is assigned the value 40.
ANS = 1000/25
* A null value is assigned to BOGEY.
BOGEY = ""
/* The value of the third element of matrix CON is assigned to be the value of the element in the sixth row, eighth column position in the matrix named MASTER2. */
MASTER2(6,8) = CON(3)
/* Assigns the second element of G to the appropriate element of MATRIX. */
MATRIX(A,F) = G(2)
* T is assigned a value of T plus 3.
T += 3
/* The value of the eighth element of matrix INCOM is increased by the value of the element found in the 30th row, column eight of MON. */
INCOM(8) += MON(30,8)
* T is assigned a value of T minus 3.
T -= 3
/* AMOUNT DUE will be concatenated onto the end of the value of T. */
T := "AMOUNT DUE"
/* The literal string "INC." is concatenated to the value found in the seventh element of matrix CUST1. */
CUST1(7) := "INC."
  • No labels