To use a comma or not: that is the question. Here are some variations on punctuating dialogue and dealing with dependent phrases and clauses. The repetition could seem mind-numbingly boring, but I wanted to write the same content in a number of different ways for clarity with respect to punctuation and capitalization.
PUNCTUATING DIALOGUE
“Come with me. You’ll have fun.” My friend held out his hand.
“Come with me. You’ll have fun,” my friend said, holding out his hand.
“Come with me. You’ll have fun,” my friend said.
“Come with me,” my friend said. “You’ll have fun.”
“Come with me.” My friend held out his hand. “You’ll have fun.”
“Come with me,” my friend said, “and we’ll have some fun.”
My friend held out his hand. “Come with me. You’ll have fun.”
My friend said, “Come with me. You’ll have fun.”
“Come with me?” my friend asked. “You’ll have fun.”
Come with me!” my friend shouted. “You’ll have fun!”
DEPENDENT PHRASES AND CLAUSES
When my friend held out her hand, I went to her.
I went to my friend when she held out her hand. (No comma here!)
Holding out his hand, he backed away. (Apply the “while” test to participle phrases.)
While holding out her hand, she backed away.
He backed away, holding out his hand.
He backed away while holding out his hand. (No comma here either.)
After holding out his hand, he backed away.
As he held out his hand, he backed away.
He held out his hand as he backed away. (No comma.)
Going with her would be fun.