next up previous contents
Next: Parametrised Intrinsic Types Up: More on Procedures Previous: Recursive Functions   Contents

Recursive Subroutines

In F90 subroutines can also be recursive. The factorial example can be implemented using a subroutine, as follows:

recursive subroutine factorial(n,n_fact) 
  integer, intent(in) :: n 
  integer, intent(out):: n_fact  
  if (n > 0) then 
   call factorial(n-1,n_fact) 
   n_fact = n*n_fact  
  else 
   n_fact=1 
  end if
end  subroutine factorial



Adrian Sandu 2001-08-26