Silverfrost Forums

Welcome to our forums

Data statement

5 Jul 2011 3:26 #8510

I now that; The DATA statement is a non-executable statement used to initialise variables. It is particularly useful for initialising arrays. It has the form:

DATA variable_list/constant_list/ [,variable_list/constant_list/] ...

Can anyone tell em the interpretation of this;

data X/7*' '

data Y/5* 'Settings'/

Please help-

5 Jul 2011 5:58 #8512

This is old Fortran syntax, but still part of the Language. Look at the following.

The first use initialises the array x so all elements have the value 0.0

The second use initialises the array y so all elements have the value 'Settings'

The third case is equivalent to the second (for variable z), but uses newer syntax.

! First
real :: x(5)
data x/5*0.0/

! Second
character(len=8) :: y(5)
data y/5*'Settings'/

! Third
character(len=8) :: z(5) = 'Settings'

The main thing to remember about DATA is it only initialises at compile time (sometimes at link time), so don't expect values to be reset when a procedure with DATA statements is called multiple times.

Please login to reply.