4.4 DATA Statement

The DATA statement assigns initial values to variables and array elements before program execution. It takes the following form:

DATA nlist/clist/[[,] nlist/clist/] . . .
nlist
Is a list containing any combination of variable names, array names, array element names, character substring names, and implied- DO lists. (RECORDs are not allowed in this list.) Elements in the list must be separated by commas.

Subscript expressions and expressions in substring references must be integer expressions containing integer constants and implied-DO variables.

An implied-DO list in a DATA statement takes the following form:

(dlist, i = n1,n2[,n3])
dlist
Is a list of one or more array element names, character substring names, or implied-DO lists, separated by commas.
i
Is the name of an integer variable.
n1, n2, n3
Are integer constant expressions. The expression can contain implied-DO variables of other implied-DO lists that have this implied-DO list within their ranges.
clist
Is a list of constants separated by commas; clist constants take one of the following forms:
c
n *c
c
Is a constant or the symbolic name of a constant.
n
Defines the number of times the same value is to be assigned to successive entities in the associated nlist; n is a nonzero, unsigned integer constant or the symbolic name of an unsigned integer constant.

Rules and Behavior

The DATA statement assigns the constant values in each clist to the entities in the preceding nlist, from left to right, as they appear in the nlist. The number of constants must equal the number of entities in the nlist.

When an unsubscripted array name appears in a DATA statement, values are assigned to every element of that array in the order of subscript progression. The associated constant list must contain enough values to fill the array.

The following list describes the relationship between nlist items and clist items:

Example

In the following example, the first DATA statement assigns zero to all 10 elements of array A and 4 asterisks followed by 2 spaces to the character variable STARS:

INTEGER A(10),  B(10)
CHARACTER BELL, TAB, LF, FF, STARS*6
DATA A,STARS /10*0,'****'/
DATA BELL,TAB,LF,FF /7,9,10,12/
DATA (B(I),  I=1,10,2) /5*1/

The second DATA statement assigns ASCII control character codes to the character variables BELL, TAB, LF, and FF. The last DATA statement uses an implied-DO loop to assign values to the odd numbered elements in the array B.


Previous Page Next Page Table of Contents