Suppose I have the following piece of code in my Fortran program:
recursive function T_GreCoDi( n, m ) result (GCD)
implicit none
integer, intent(in) :: n, m
integer :: GCD
select case(n)
case(0)
select case(m)
case(0)
print *, 'both of your numbers are zeros. GCD = -1'
GCD = -1
case default
GCD = m
end select
case(1)
GCD = 1
case default
select case(m)
case(0)
GCD = n
case(:n)!<--THIS IS PROBLEM
GCD = T_GreCoDi(n-m, m)
case default
GCD = T_GreCoDi(m-n, n)
end select
end select
end function T_GreCoDi
When compiled it causes the error:
Error: Parameter 'n' at (1) has not been declared or is a variable, which does not reduce to a constant expression
So my question: Is there a way to solve this ( I still want to use case-statement)?
It is easy to avoid this error just by using if-statement instead case-statement but I want to use case- for integrity of my code.