Is there any way to run a loop for discrete values of a variable? What about in some latest version?
Something like
for i in 1 5 9 11 31 77
used in Unix shell script?
Is there any way to run a loop for discrete values of a variable? What about in some latest version?
Something like
for i in 1 5 9 11 31 77
used in Unix shell script?
integer, dimension (5) :: indx = [5, 9, 11, 31, 71]
do i=1, size(indx)
j=indx(i)
....
end do
You can also use an implied do loop to accomplish this, but you'll have to define the array of values as above:
integer, dimension (5) :: indx = [5, 9, 11, 31, 71]
integer, dimension (5) :: rslt
integer, external :: func
rslt = (/ func(indx(j)), j=1,5 /)
I am not sure if this helps, but you can use arrays for indeces
program Console1
implicit none
! Variables
INTEGER :: X(4) = (/ 1, 3, 5, 7 /)
REAL :: Y(10) = 0.0
! Body of Console1
print *, X
! 1 3 5 7
Y(X) = 10.0/X
print *, Y
! 10.0 0.0 3.33 0.0 2.00 0.0 1.428 0.0 ...
end program Console1