When someone burps in a quiet classroom it can be hard to refrain from laughing. Use the verb refrain if you have a sudden impulse to do something, and you have stopped yourself from doing it.
It's usually hard to refrain from doing something, because this word is used to describe habits, like smoking, or uncontrollable urges, like laughing. The Latin word refrēnāre is formed from the prefix re- "back" plus frēnāre "to hold a horse back with a bridle." There is a noun refrain, but that's a different and unrelated word.