c=========================================================== c go-to-less version of mysum. No more or less correct c than go-to-full version, of course, but some would assert c that this version is "cleaner"/"safer" in some sense, c or at the very least, better stylistically. c=========================================================== program mysum implicit none real*8 vi, sum integer rc, rceof, nbad nbad = 0 sum = 0.0d0 c----------------------------------------------------------- c 'rc' will be set to a NEGATIVE value when end of file c is encountered. Initialize 'rc' to 0 to ensure that c we get into the 'do while' loop. c----------------------------------------------------------- rc = 0 do while ( rc .ge. 0 ) read(*,*,iostat=rc) vi if( rc .eq. 0 ) then sum = sum + vi c----------------------------------------------------------- c New logic to ensure that EOF doesn't get counted c as a bad input. c----------------------------------------------------------- else if ( rc .gt. 0 ) then nbad = nbad + 1 end if end do write(*,*) sum if( nbad .gt. 0 ) then write(0,*) nbad, ' invalid inputs' end if stop end