Bob Harper, a trainer and host of NBC’s weight-loss reality television show “The Biggest Loser,” had a heart attack in February, he said in an Instagram post on Tuesday.

“I am feeling better,” Harper said. The 51-year-old fitness professional has trained teams for more than 200 episodes of “The Biggest Loser,” which he began hosting in 2004. Harper collapsed during a workout at a New York City gym, TMZ reported. He was unconscious for two days before waking up in a hospital.

Harper, a health and diet celebrity, was selected by the People for the Ethical Treatment of Animals as “Sexiest Vegetarian” in 2010, along with actress Olivia Wilde. (He became a vegan in 2010 but resumed eating meat in 2013, he told Reuters.)

According to TMZ, he laid the blame for the attack squarely on genetics. A family history of heart disease is a known risk factor for children to have adverse cardiovascular events.

As for exercise, scary anecdotes about heart attacks or other cardiac events during workouts should not steer anyone from moderate physical activity, experts advise.

“There is unequivocal evidence that regular physical activity and exercise have multiple benefits that far outweigh any risk of the exercise itself,” Jonathan A. Drezner, a physician and sports medicine specialist at Seattle’s University of Washington, told the Wall Street Journal in 2015. His comments came after the death of James B. Lee Jr., 62, a prominent banker for JPMorgan Chase who died shortly after exercising.

In 2015, a team of American and French doctors analyzed 1,247 cases of sudden cardiac arrest (which is an electrical malfunction of the heart, not to be confused with a heart attack caused by accumulated arterial plaque) in middle-aged women and men. As they reported in the journal Circulation, only 63 cases, or 5 percent of cardiac arrests, occurred while people were exercising.

“These deaths grab our attention because they’re rare and counter-intuitive,” Massachusetts General Hospital’s Aaron L. Baggish, who was not involved with the research, said to Harvard Heart Letter when the study was published. “But there’s absolutely no question that regular, moderate-intensity exercise is the best way to prevent sudden cardiac arrest.”

On Instagram, Harper complimented his nurse, Karl, and thanked his fans for support and said that he was “just taking it easy.”

Correction: A previous version of this post described Jonathan A. Drezner as a sports cardiologist; he is a physician and specialist in sports medicine.

More from Morning Mix

Subway chicken in Canada was part meat, part something else, according to DNA analysis

Obamas sign book deals with Penguin Random House