# 10 ASSIGNMENT STATEMENTS

Completion of execution of an assignment statement causes definition of an entity.

There are four kinds of assignment statements:

1. Arithmetic
2. Logical
3. Statement label (ASSIGN)
4. Character

## 10.1 Arithmetic Assignment Statement

The form of an arithmetic assignment statement is:
`v = e`
• where: v is the name of a variable or array element of type integer, real, double precision, or complex
• e is an arithmetic expression

Execution of an arithmetic assignment statement causes the evaluation of the expression e by the rules in Section 6, conversion of e to the type of v , and definition and assignment of v with the resulting value, as established by the rules in Table 4.

Table 4

Arithmetic Conversion and Assignment of

e to v
```               _________________ __________
|                 |          |
| Type of v       |  Value   |
|_________________|__Assigned|
|                 |          |
| Integer         |  INT(e)  |
|_________________|__________|
|                 |          |
|_Real____________|__REAL(e)_|
|                 |          |
| Double precision|  DBLE(e) |
|_________________|__________|
|                 |          |
|_Complex_________|__CMPLX(e)|
```

The functions in the "Value Assigned" column of Table 4 are generic functions described in Table 5 ( 15.10).

## 10.2 Logical Assignment Statement

The form of a logical assignment statement is:
`v = e`
• where: v is the name of a logical variable or logical array element
• e is a logical expression

Execution of a logical assignment statement causes the evaluation of the logical expression e and the assignment and definition of v with the value of e . Note that e must have a value of either true or false.

## 10.3 Statement Label Assignment (ASSIGN) Statement

The form of a statement label assignment statement is:
`ASSIGN s TO i`
• where: s is a statement label
• i is an integer variable name

Execution of an ASSIGN statement causes the statement label s to be assigned to the integer variable i . The statement label must be the label of a statement that appears in the same program unit as the ASSIGN statement. The statement label must be the label of an executable statement or a FORMAT statement.

Execution of a statement label assignment statement is the only way that a variable may be defined with a statement label value.

A variable must be defined with a statement label value when referenced in an assigned GO TO statement ( 11.3) or as a format identifier ( 12.4) in an input/output statement. While defined with a statement label value, the variable must not be referenced in any other way.

An integer variable defined with a statement label value may be redefined with the same or a different statement label value or an integer value.

## 10.4 Character Assignment Statement

The form of a character assignment statement is:
`v = e`
• where: v is the name of a character variable, character array element, or character substring
• e is a character expression

Execution of a character assignment statement causes the evaluation of the expression e and the assignment and definition of v with the value of e . None of the character positions being defined in v may be referenced in e . v and e may have different lengths. If the length of v is greater than the length of e , the effect is as though e were extended to the right with blank characters until it is the same length as v and then assigned. If the length of v is less than the length of e , the effect is as though e were truncated from the right until it is the same length as v and then assigned.

Only as much of the value of e must be defined as is needed to define v . In the example:

1. CHARACTER A*2,B*4
2. A=B

the assignment A=B requires that the substring B(1:2) be defined. It does not require that the substring B(3:4) be defined.

If v is a substring, e is assigned only to the substring. The definition status of substrings not specified by v is unchanged.

[Contents] [Previous] [Next] [Home]

NDP77
http://www.ndp77.net
webmaster MFA (main)
webmaster@ndp77.net