This was a 5 year old though...
Yeah, that's the point.
Teach a 5 year old that telling a bad-word gets your lesson ended and you are teaching him to love the prohibite thrill of bad-words and he will grow a person loving being vulgar.
Teach him that it's not a big deal, that everyone does that but it's still better to think before impulsive swearing and he will understand and will grow a way less vulgar person.
After all the "adults" we complain about nowadays, the sexist, the arrogant, the vulgar, the homophobic, the greedy, the egotist, the egocentric have all be educated through the orthodox way of telling children not to swear, punishing them for whatever thing they do, allowing them no freedom to explore there's a violent and bad side to the world, talking down to them, asking them to be always polite even if adults rarely are ... and it just haven't worked. Maybe, just for the sake of getting better results, it's time to try something new and to admit that whatever experts and non-experts believe to know about educating children is just plain flawed. There's this myth that when you meet a superficial and aggressive teen his parents must have been too permissive, absent and allowing him to swear and watch bad movies. It's actually the opposite: those are the children of non-permissive and easily scandalized parents who infantilize their children, treat them ike delicate flowers, supervise their lives strictly and doesn't allow children the same human mistakes adults get away with all the time.