What is the difference between "data" versus "=" in Fortran?

Viewed 45

I am new to Fortran and I'd like to understand the differences between these two statments:

logical :: TF
TF = .true.

and:

logical :: TF
data TF/.true./

Please keep the response in more simple to words, I've recenetly moved from Python to this compiled language. Thanks!

1 Answers

Loosely, a DATA statement performs explicit initialization of a variable. An assignment statement gives a variable a value.

These are very different things. You can consider the DATA statement version of this question like

logical, save:: TF=.TRUE.

and see many questions/complaints about how this behaves unexpectedly.

In general, it's worth noting that DATA statement and the "declaration with SAVE" (actually an initialization on declaration) are also (subtly) different. As a beginner, perhaps pretend these initializations don't exist and stick to assignment.

Related