Declare variables anywhere

… … Picture display is also a way of presentation :lying_face:
Online Compiler: Compiler Explorer (godbolt.org)

program foo
    call block1
    print *
    call block2
    print *, "Normal exit."
end program foo
!
! For an implicitly declared variable (e.g., i and j here), the
! scope of the variable is from the inclusive scoping unit.  That
! is, 'j = 1' in block1 is implicitly declared to be in the
! namespace of block1.  In addition, the implicitly declared 'i'
! in block bah is also in the namespace of block1.
!
subroutine block1
    j = 1
    bah: block
        i = 42
        j = 42
    end block bah
    if (i /= 42) print *, 1, i  ! i should be 42
    if (j /= 42) print *, 2, j
end subroutine block1
!
! In the following 'i' has an implicit declaration in the scope
! of block2.  The explicit declaration of 'i' in block bah means
! that this 'i' has the scope of bah.
!
subroutine block2
    i = 1
    j = 1
    bah: block
        integer i
        i = 42
        j = 42
        if (i /= 42) print *, 3, i
        if (j /= 42) print *, 4, j
    end block bah
    if (i /= 1) print *, 5, i
    if (j /= 42) print *, 6, j
end subroutine block2