@Russel Your code causes me to disconnect. And also causes Mirc to freeze in an infinite loop.

Actually, I tested my code to see if it worked or not. I didn't think it would work for the exact reason you gave, but it does. I believe the script gets done sending all the commands before you actually leave the channels.

If I was writing it over again, I'd probably get a list of channels and then once the while loop is done processing, part all the channels on the list. I think that's the safest way to do it.