Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

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

Guillaume_De_Nayer
740 Views

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
1 Solution
Xiaoping_D_Intel
Employee
740 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
Xiaoping_D_Intel
Employee
741 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

 

 

 

 

0 Kudos
Guillaume_De_Nayer
740 Views

Thx a lot for your quick reply!

0 Kudos
TimP
Honored Contributor III
740 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
Reply