I use Fortran and I was wondering if it's possible to make something like that
do i = array
write (*,*) i
end do
where array is a list of integer numbers not necessarily ordered.
Implied DO loops are DO loops in the sense that they control the execution of some iterative procedure, but are different than DO loops because they do not use the do statement to control the execution.
Exit statement terminates the loop or select case statement, and transfers execution to the statement immediately following the loop or select.
It starts with a (, followed by a set of items, separated by commas, followed by a DO variable, an equal sign, an initial value, a final value, and a step-size, end ends with a ). Like a typical DO-loop, if the step size is 1, it can be eliminated.
I would introduce a second index to iterate over the elements of an array:
program test
implicit none
integer, dimension(6) :: A
integer, dimension(10) :: B
integer :: i, j
A = (/ 1, 3, 4, 5, 8, 9 /)
B = (/ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 /)
do j = 1, size(A)
i = A(j)
write(*,*) i, B(i)
end do
end program test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With