Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fortran allows declaration of variables within loops, contrary to what PWR002 says #1

Closed
Beliavsky opened this issue Jan 25, 2024 · 3 comments

Comments

@Beliavsky
Copy link

Beliavsky commented Jan 25, 2024

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:

program main
implicit none
integer :: i
do i=1,5
   block
      integer :: isq
      isq = i**2
      print*,i,isq
   end block
end do
end program main

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.

@daniel-otero
Copy link
Contributor

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!

@jalvesz
Copy link

jalvesz commented Jan 26, 2024

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

@alvrogd
Copy link
Contributor

alvrogd commented Mar 1, 2024

Resolved in #9! Thank you all for your feedback :)

@alvrogd alvrogd closed this as completed Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants