I’m trying to implement the fibonacci solution using iterative method. It all works well except that the tmp variable remembers the values of temporary variables for the next function call.

Here’s the code that I’ve written

```
program fibonacci
use, intrinsic :: iso_fortran_env, only : i8=>int64, error_unit
implicit none
integer :: n=5
integer(i8) :: f1, f2
print *, fib(n), fib(n), fib(n)
print *, fib(n)
contains
function fib(n) result(f) ! iterative
integer,intent(in) :: n
integer(i8) :: f
integer(i8) :: tmp=0, f_1=1
integer :: i=0
if (n <= 0) then
write(error_unit, *) 'n must be a positive integer'
stop 1
end if
f=f_1
do i = 2, n
tmp=f
f = f + f_1
f_1 = tmp
end do
end function fib
end program fibonacci
```

This gives the following output.

```
8 40 200
1000
```

It looks like the `tmp`

and `f_1`

are remembering the values between function calls. What am I doing wrong here? Isn’t it supposed to remember the variable values only if `save`

is mentioned? Please let me know.

Thanks in advance!