File: nested_21.f90

package info (click to toggle)
lfortran 0.60.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,412 kB
  • sloc: cpp: 173,406; f90: 80,491; python: 17,586; ansic: 9,610; yacc: 2,356; sh: 1,401; fortran: 895; makefile: 37; javascript: 15
file content (59 lines) | stat: -rw-r--r-- 1,138 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
! Check sync statements in do while loops 
! at cycle statements for scalar and arrays
module temp_nested_21

contains
  subroutine demo()
    implicit none
    integer :: a,c
    integer :: arr(2)
    a = 1
    ! Variable c is used to not run loops indefinitely
    c = 1
    ! Scalar checks
    do while(f())
        if (c>10) error stop
        c = c + 1
        if (a < 5) then 
          a = a + 1
          cycle
        end if
        if (a > 4) error stop
    end do
    print *, a
    if (a < 4) error stop

    ! Array Checks
    c = 1
    arr(2) = 1
    do while(g())
        if (c>10) error stop
        c = c + 1
        if (arr(2) < 5) then 
          arr(2) = arr(2) + 1
          cycle
        end if
        if (arr(2) > 4) error stop
    end do
    print *, arr(2)
    if (arr(2) < 4) error stop

  contains
    logical function f()
      print *, a
      f = (a < 4) 
    end function f

    logical function g()
      print *, arr(2)
      g = (arr(2) < 4) 
    end function g

  end subroutine demo 
end module temp_nested_21

program nested_21
  use temp_nested_21
  implicit none
  call demo()
end program nested_21