Pick up the return code for every iteration and display the result only once in loop.

Hi All,
I amlearning UNIX scripting. I have a small query. I would be thankful if any one helps me out.

I have a below piece of code which delets the files. If file dosent have the permissions to delete a particular file I have used 2>>operator to track the error code.

But my objective is to check the return of 'rm' for every iteration.
Some thing like we should be picking up the return code, if its value is greater than 0 then you should set a flag to indicate that an error has occured.
The flag should be initialised to zero before the iterations begin. And the error message some thing like 'Atleast one file cannot be deleted'.

Example:-we need to remember using a flag (something like if [[ $? > 0 ]] then rm_errorflag=1). Need to use this in below piece of code

ls -l | { while read myline;
do
if [[ -f "$myline" && "$myline" != *.ksh ]]
then
echo "Removing " "$myline" >> temp
rm -f "$myline" 2>>temp
fi
done }

Please help me out in this.
Thanks for your time.

Regards,
Manas

add to this to the end of the rm line:

rm -f "$myline" 2>>temp || rm_errorflag=1

which will set the rm_errorflag if rm's exit value is greater than 0