How to skip a few iterations in a do loop in Fortran

后端 未结 2 547
情话喂你
情话喂你 2021-01-15 04:54

For example, I want to loop from 1 to 500 at an increment of 2. However, for every 8 loops I want to skip the next 18 loops (make the do-variable increase by 18). How do I d

相关标签:
2条回答
  • consider a nested loop for this example, something like

      do k=0,15
        do j=0,7
          i=34*k+2*j  ! 34 == 18+2*8
            ....
       end do
      end do
    

    (probably i don't have the arithmetic right but you see the idea)

    0 讨论(0)
  • 2021-01-15 05:31

    It is forbidden to modify the loop index. You can solve your problem in several ways. For instance, here is a solution without explicit loop index :

    i = -1
    do
        i=i+2
        if(i > 5000) exit
        if (i == 15) i=i+18
        ...
    enddo
    
    0 讨论(0)
提交回复
热议问题