Pitfalls of using chatgpt to generate Fortran code

It is correct that the integer t cannot be declared as a parameter and then used as a variable, but the do loop itself is otherwise allowed. This example is legal:

program do
   integer :: t=4
   do t = 1, t
      write(*,*) t
   enddo
end program do

The capitalization of course does not matter. This is allowed because in fortran the trip count is evaluated before the do index is assigned its values within the loop. This kind of variable usage is not allowed in most other languages.

2 Likes