Your code is not standard-compliant. That is: from F2008 5.2.3:
A variable, or part of a variable, shall not be explicitly initialized more than once in a program.
The DATA
statement (is one thing that) performs such explicit initialization (5.4.7.1), and so in particular two cannot appear for the same variable.
For your second "initialization", use assignment. [As given by @VladimirF who is a faster typist than I.] Further, while one can put a DATA
statement with executable statements, as in this case, the standard goes as far as making that obsolescent (B.2.5):
The ability to position DATA statements amongst executable statements is very rarely used, unnecessary, and a potential source of error.
As the code is non-standard, and the error is not one the compiler is required to detect, the compiler is free to whatever it likes with the code. I thought it would be interesting to see what we do see with a small selection:
- One refused to compile (and also pointed out the obsolesence);
- Two quietly went ahead, using the first initialization;
- One used the second initialization, warning.
Of course, one wouldn't want to rely on any of these behaviours, even if it was a desired one.