It's not a simple matter of "always use 'of' before a word ending in -ing" or "always use 'for' ...". It depends on the context of the whole sentence. It would depend more on the word that precedes the "of" or "for" than on the word that follows. Like you would write, "What is your reason FOR doing that?" but "What is the result OF doing that?"
"Of" and "for" have fairly similar meanings. I'm trying to think of a general rule about when you use either. "Of" generally means "belonging to" while "for" means "related to the purpose of". For example, "book of mine" means the book I own. "Book for math class" means a book intended to be used in math class. But there are so many shades and ranges of meaning that this is really inadequate. I fear you have to take them case by case.