! ------------------------------------------ ! Example program ! ! Demonstrates how the k in the ! contained subroutine ! *is* the same k as in the main program: ! Except if you make a small mistake! ! ------------------------------------------ Program test implicit none integer:: i,k=100 do i = 1, 5 call addone print*,'k in main routine = ',k end do contains subroutine addone ! integer:: k ! Uncomment this line to make a mistake k = k + 1 ! this print statement is added to see what k is print*,'k in subroutine = ',k end subroutine addone end program test