File: procedure_12.f90

package info (click to toggle)
lfortran 0.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 46,332 kB
  • sloc: cpp: 137,068; f90: 51,260; python: 6,444; ansic: 4,277; yacc: 2,285; fortran: 806; sh: 524; makefile: 30; javascript: 15
file content (38 lines) | stat: -rw-r--r-- 929 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module procedure_12_mod

contains

   recursive subroutine sub(int, X)
      integer, intent(in) :: int
      integer, intent(inout) :: X(:)
      procedure(sub), pointer :: proc 
      proc => sub
      
      if (int <= 5) X(int) = int
      if (int > 5) return
      if (mod(int, 2) /= 0) then
         print *, "Odd: ", int
         call proc(int + 1, X)
      else
         proc => alt_sub
         call proc(int, X)
      end if
   end subroutine sub

   subroutine alt_sub(int, X)
      integer, intent(in) :: int
      integer, intent(inout) :: X(:)
      if (int <= 5) X(int) = int
      print *, "Even: ", int
      call sub(int + 1, X)
   end subroutine alt_sub

end module procedure_12_mod

program procedure_12
   use procedure_12_mod
   integer :: X(5) = [0, 0, 0, 0, 0]
   call sub(1, X)
   print *, X
   if(X(1) /= 1 .or. X(2) /= 2 .or. X(3) /= 3 .or. X(4) /= 4 .or. X(5) /= 5) error stop
end program procedure_12