Need help with pattern matching to list missing packages

I have wrote this small program to check for installed and missing packages in LINUX (RHEL x86_64)

For now it perfectly prints all the installed and missing packages however I want that it loops through to the end (in either case) and
list all packages however if one or more packages are found missing then program should terminae

here is program

#echo ""
echo "Checking for installed packages...please wait"
echo ""

for  PACKAGE in binutils.x86_64 compat-libstdc++-33.x86_64  glibc-common.x86_64 glibc.x86_64 glibc-devel.x86_64 \
glibc-headers.x86_64  ksh.x86_64 libaio.x86_64 libaio-devel.x86_64 libgcc.x86_64  libstdc++.x86_64 libstdc++-devel.x86_64 make.x86_64 \
  compat-libcap1.x86_64 gcc.x86_64 gcc-c++.x86_64 glibc-devel.x86_64  libstdc++.x86_64 libstdc++-devel.x86_64 sysstat.x86_64
do
if yum list installed $PACKAGE >/dev/null 2>&1;
then
echo "$PACKAGE is installed"
else
echo "$PACKAGE not installed"
fi

done

Code snipped:

if yum list installed $PACKAGE >/dev/null 2>&1;
then
  echo "$PACKAGE is installed"
else
  echo "$PACKAGE not installed"
  exit 1
fi

The exit 1 statement causes the loop and the script both to terminate. Also the return code will be a failure. Is this what you meant?

no, i think exit 1 will end the loop as soon as first occurance of 'non installed' pacakge will be encountered. I dont want loop to end - #i want it to complete until it checks last package mentioned in for loop and thn exit if found any missing package.

hi,

forpackage in <list of packages>
do
   if <installed>
   then <package ok>
   else <nogo for package>; nogo=1
   fi
done
test $nogo -ge 1 && exit 1

why wouldn't you make the script to stop as soon as it detects a missing package ?

Because than there may b last package missing - so i want to loop through all of them then list those which are missing - so that we can go back to Unix support and ask them to install the missing packages in one request, the program must also exit after listing missing packages. If none found missing than program should continue

Thanks

Why don't you yum list all installed packages and then check against your list? Would have the advantage running yum just once instead of once per package.