Closed Beliavsky closed 8 months ago
You are right. We completely missed the Fortran 2008 BLOCK
feature. We take note, and we will soon update the rule accordingly.
We will let you know when the wording gets updated. Until then, the issue will remain open.
Thank you very much!
Just a small change in the code snippet to showcase what @Beliavsky tried to show:
program main
implicit none
integer :: i
do i=1,5
block
integer :: isq !> variables can be defined here
isq = i**2
print*,i,isq
end block
end do
end program main
Resolved in #9! Thank you all for your feedback :)
The statement that "the Fortran programming language does not allow to declare variables inside loops, in the statements of the loop body." at https://github.com/codee-com/open-catalog/tree/main/Checks/PWR002 is incorrect, since Fortran 2008 introduced the BLOCK construct, described at https://www.ibm.com/docs/en/xffbg/121.141?topic=control-block-construct-fortran-2008 . For example, the following code compiles and runs with gfortran:
Note: the original code did not correctly demonstrate that
isq
can be declared within a loop, as @jalvesz points out below. I have corrected the code.