PROGRAM TableLookUp
   IMPLICIT NONE
   INTEGER, PARAMETER                 :: TableSize = 100
   INTEGER, DIMENSION(1:TableSize)    :: Table
   INTEGER                            :: ActualSize, Key, Location
   INTEGER                            :: I

   READ(*,*) ActualSize
   READ(*,*) (Table(I), I=1, ActualSize)

   DO
      WRITE(*,*) 'A search key, please (0 to exit)  -> '
      READ(*,*) Key
      IF (Key == 0) EXIT
      Location = LookUp(Table, ActualSize, Key)
      IF (Location > 0) THEN
         WRITE(*,*) Key, ' appears in location ', Location
      ELSE
         WRITE(*,*) Key, ' is not found.'
      END IF
   END DO

CONTAINS
   INTEGER FUNCTION LookUp( x, Size, Data)
      IMPLICIT NONE
      INTEGER, DIMENSION(:), INTENT(IN) :: x
      INTEGER, INTENT(IN)               :: Size, Data
      INTEGER                           :: I

      LookUp = 0
      DO I = 1, Size
         IF ( x(I) == Data ) THEN
            LookUp = I
            EXIT
         END IF
      END DO
   END FUNCTION LookUp
END PROGRAM TableLookUp
