Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
40 Views

DO LOOP with an upper limit smaller than the lower limit and with a positive step

Jump to solution

Hi,

I have a very simple question: What should a FORTRAN compiler do with a DO LOOP with an upper limit smaller than the lower limit and with a positive step?

I wrote a small code

       program test_loop_1_0
       integer :: i,imax

       imax=0

       call loop(imax)

       end program

c---------------------------
       subroutine loop(imax)
       integer :: i,imax
       do i=1,imax
         PRINT*,"DBG",i
       enddo
       end subroutine loop

This code compiled with ifort shows that a DO i=1,0 ENDDO produces no iteration. Is this behavior written in the FORTRAN standards?

Thx a lot,

Best regards

Guillaume

 

0 Kudos

Accepted Solutions
Highlighted
40 Views

Yes. it is the behavior defined in the fortran standard. For example, according to F2003 standard "8.1.6.4.1 Loop initiation" the loop iteration count of your code will be zero, then according to "8.1.6.4.2 The execution cycle" if the iteration count is zero the loop will terminate.

 

It is also written in Intel Fortran Compiler documentation at https://software.intel.com/en-us/node/579912

 

Thanks,

Xiaoping Duan

Intel Customer Support

 

 

 

 

View solution in original post

0 Kudos
3 Replies
Highlighted
41 Views

Yes. it is the behavior defined in the fortran standard. For example, according to F2003 standard "8.1.6.4.1 Loop initiation" the loop iteration count of your code will be zero, then according to "8.1.6.4.2 The execution cycle" if the iteration count is zero the loop will terminate.

 

It is also written in Intel Fortran Compiler documentation at https://software.intel.com/en-us/node/579912

 

Thanks,

Xiaoping Duan

Intel Customer Support

 

 

 

 

View solution in original post

0 Kudos
Highlighted
40 Views

Thx a lot for your quick reply!

0 Kudos
Highlighted
Black Belt
40 Views

This behavior has been required since the Fortran 77 standard.  The original Fortran 66 standard didn't define trip count in this situation, although the most widely used compilers had the one-trip behavior, and programs were written frequently on that assumption.

0 Kudos