I had a similar problem with a mail program - it was reported after someone tried to delete all the mail they didn't want via check boxes, and ended up deleting everything they hadn't selected.... I spent the remainder of that day under my desk 🙂
The problem was the increment in my for loop was taking place before the next action took place.
Have a look at your increments when you're looping with delete - try and echo them and see where it's going wrong.
Hope this helps!
Regards,
-m.