Dear friends, I have to perform a recursive procedure within a subroutine, something, for example, like this:
module xxxx
…
subroutine rrrr ! (for simplicity I don’t state the intent of the variables)
A = A + b*50
end subroutine rrrr
end module xxxx
program yyyy
use xxxx
…
do i = 1,100
call rrrr()
end do
…
end program yyyy
My doubt is that I do not know where to put the initial value of A = 0. For example, if I place it within the module before the subroutine, every time the subroutine is called, will A be set = 0? In this case, it won’t work. Therefore, could you please help me understand where A should be placed in such a code?
I don’t see recursion in your example.
A rather useless recursive program is given below
program xxxx
implicit none
print*, rrrr(100.)
contains
recursive function rrrr(u) result(A)
real, intent(in) :: u
real :: A
print*, 'u', u
if (u < .5) then
A = u
else
A = rrrr(u/2.)
endif
end function rrrr
end program xxxx