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
|