numindex is declared but not assigned a value. It stays at its default value of 0.
There are no default values unless you provide default initialization in the declaration of the variable(s) concerned, or use a 'save my skin' option such as /zero.
DavidB is an experienced and expert programmer. His advice merits careful consideration.
Optimization and bug checking do not go well together. Any time spent doing runtime checking is time that, in bug-free code, would have been used profitably in computing good results.
The Fortran language has certain rules. If you knowingly break the rules, and conclude that 'I saw no evil, therefore there is no evil', you may be in for a very unpleasant surprise some day. Bugs can remain dormant for a long time. Some bugs even disappear when you look for them (they are called Heisenbugs). Don't take things for granted, and don't generalize from your experience without a sound basis.
Here is a fleshed out version of your code to help you understand the issues.
program tstuninit
implicit none
logical :: inputisnumber = .true.
integer :: numindex,k,numberofinputs=50,input(50),numvalue=-5
do k = 1, numberofinputs
If (inputisnumber) then
numindex = numindex+1
Input(numindex) = Numvalue
endif
enddo
if (Input(numindex) .eq. 1) then
write(*,*)Input(2)
endif
end program
If you compile and run with the /check option, the program will stop at the line where *numindex *is used as a subscript in the loop. If you next compile and run with the /undef option, the program will stop at the [u:7352073a01]previous [/u:7352073a01]line, where the uninitialized value is used. If you compile with /zero, when run the program will probably crash with a mysterious access violation.