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

faulty compiler error #6526

WSinc
New Contributor I
611 Views

This is a simplied version of something I submitted earlier.

program Console11
    integer i1,i2,i3,i4,j
    do 10 i1=1,10     
      do 10 i2=1,10
        if(i2==i1)go to 10
        do 20 i3=1,10
          if(i3.eq.i2 .or. i3.eq. i1) go to 20
          do 20 i4=1,10
            if(i4.eq.i3.or. i4.eq.i2 .or. i4 .eq.i1)go to 20
            j=i1+i2+i3+i4

20 enddo
10 enddo
    end program

This wont compile, unless I add another enddo line, i.e.

that I use Do 30, I4=1,10

I think the presence ot the IF statements causes the problem.

I want to get Unique values of i1,i2,i3, and i4

0 Kudos
4 Replies
Steven_L_Intel1
Employee
611 Views

Your program is faulty, not the compiler. The compiler's error message is exactly on target, though it's highlighting the wrong line

t.f90(7): error #6526: A branch to a do-term-shared-stmt has occurred from outside the range of the corresponding inner-shared-do-construct.   [20]
          do 20 i4=1,10
-------------^

When you have shared DO termination (an obsolescent feature), the termination belongs to the innermost loop. The line:

if(i3.eq.i2 .or. i3.eq. i1) go to 20

is part of the outermost loop and therefore a branch into the inner loop is not allowed.

Don't use shared DO termination. Instead of GOTO, consider  CYCLE with a labeled loop.

0 Kudos
mecej4
Honored Contributor III
611 Views

billsincl wrote:
I want to get unique values of i1,i2,i3, and i4

Your specification is incomplete. Do you want just one quartet of distinct integers between 1 and 10? Or do you want to list all such quartets? If the latter, here is code that does it without using labels (caution: there are thousands of -- 10*9*8*7, to be precise -- lines printed out!).

If you wish to rule out permutations, you need to modify the code.

The obvious solution, [1, 2, 3, 4] has the virtue that the items add up to 10, the upper bound of the range of values permitted.

program quartet
implicit none
integer :: i1,i2,i3,i4
logical :: used(10) = .false.

do i1 = 1, 10
   used(i1) = .true.
   do i2=1,10
      if (used(i2)) cycle
      used(i2) = .true.
      do i3 = 1, 10
         if (used(i3)) cycle
         used(i3) = .true.
         do i4 = 1, 10
            if (used(i4)) cycle
            write(*,'(4I4)')i1,i2,i3,i4
         end do
         used(i3) = .false.
      end do
      used(i2) = .false.
    end do
    used(i1) = .false.
end do
end program

 

0 Kudos
jimdempseyatthecove
Honored Contributor III
611 Views
program Console11
 integer i1,i2,i3,i4,j
 do i1=1,10     
   do i2=1,10
     if(i2==i1) cycle
     do i3=1,10
       if(i3.eq.i2 .or. i3.eq. i1) cycle
       do i4=1,10
         if(i4.eq.i3.or. i4.eq.i2 .or. i4 .eq.i1) cycle
         j=i1+i2+i3+i4
         write(*,'(4I4)')i1,i2,i3,i4
       enddo ! i4
     enddo ! i3
   enddo ! i2
 enddo ! i1
end program

Jim Dempsey

0 Kudos
andrew_4619
Honored Contributor II
611 Views

Steve Lionel (Intel) wrote:
consider  CYCLE with a labeled loop.

Well you learn something new every, I didn't know CYCLE (and more usefully EXIT) can use a loop label to trip out of more than one level of loop nesting! Cheers!

0 Kudos
Reply