As you push toward an ambitious goal, you hit roadblocks. Pain sets in. You want to quit.

Top leaders swat away irritants, keep going and adopt a winner’s attitude. How to train your mind to persevere and attain victory:

Shift your perspective. Chasing a goal is easy when everything goes well. But when speed bumps slow your momentum, doubts can creep into your head and trigger a downhill spiral.

“Reframe the pain from a negative to a positive,” said Loren Fogelman, a business coach in Medford, Ore. “When you’re negative, the body tightens up, feeds into the pain and makes you more aware of it.”

A competitive rower, Fogelman used to respond to adversity by thinking, “I can’t do another 50 meters.” But she learned to overcome her physical pain by adopting a rallying cry such as, “I can do anything for 50 meters.”

Author of “The Winning Point,” Fogelman teaches entrepreneurs to engage in similar reframing amid setbacks. She might advise them to replace mental messages such as “I botched my new product rollout” with “now I can make great changes to my product.”

Impose logic. Facing an uphill battle in pursuing a goal, you might blow the situation out of proportion. Thoughts such as “this is the worst!” or “I can’t believe my bad luck” can crush your spirits.

Instead, focus on the facts. Think of yourself as what executive coach Doug Hensch calls “an upbeat scientist.”

“Separate what you know from what you don’t know,” said Hensch, the Leesburg, Va.-based author of “Positively Resilient.” “Argue with yourself. Identify what evidence you’re missing. Assess whether your doubts are accurate.”

Create a playlist. To stay mentally engaged during her long-distance ocean swims, Diana Nyad devised a playlist of her favorite songs. Aside from enjoying the melodies and lyrics, she found that the rhythms matched the cadence of her stroke.

“I’m not using headphones. I just hear the song in my brain,” she writes in her memoir “Find a Way.” “I need tunes that my brain wants to engage in for hours at a time.”

Break it down. If you ponder the enormity of the goal you’re seeking, you can lose yourself in the magnitude of your quest. The whole exercise can prove too intimidating or overwhelming.

It’s smarter to break a lofty goal into digestible chunks. That way, you can set and achieve lots of mini-goals along the way.

“Focus on bite-size pieces,” said Caroline Adams Miller, a speaker and performance coach in Bethesda, Md. If you’re running a marathon, don’t dwell on all the miles left to the finish line. Instead, keep setting little goals such as, “I’ll reach the next landmark in five minutes.”

Gain inspiration. As tough as you fight to achieve a goal, realize that you’re lucky to have the opportunity. Derive strength from those who live in your memory.

Co-author of “Creating Your Best Life,” Miller cites examples of athletes who conquer adversity by recalling beloved deceased grandparents or victims of the 9/11 attacks “who never had a chance to live out their dream.”

Choose uplifting stimuli. Environmental factors can motivate you or sap your will. So place yourself in surroundings filled with stirring sensory cues.

“Prime your environment with pictures, sounds and colors that give you bold, directive thoughts,” Miller said. Choose log-in passwords that reflect your goals. Customize your car’s license plate with a message that reinforces your drive to excel.

Miller even programs her mobile phone ringer to play “Happy” by Pharrell Williams. The cheery tune doubles as her morning alarm.