A new study published in this month’s Journal of the American College of Cardiology found that erectile dysfunction (ED) is often an early indicator of poor cardiovascular health. Researchers followed more than 2,300 men for an average of four years and found that men with ED had a 58 percent greater risk of coronary heart disease.

The fact is, the very same habits that predispose a man (or a woman) to health problems, such as too little exercise, a poor diet, smoking and other lifestyle choices, also take a toll on sexual function. This study suggest that problems in the bedroom may be an important warning sign to shape up — if not for your sex life, then for your quality of life.

In his book on male sexual health, The Hardness Factor, Dr. Steven Lamm cites a British study in which men who reported having three or more orgasms per week experienced 50 percent fewer heart attacks and strokes than men who had less sex. Lamm’s book was inspired by the correlations he made in his own practice between the erectile problems among his male patients and conditions such as obesity, high cholesterol, hypertension, depression, sleep disorders, diabetes and heart disease.

According to Dr. Lamm, “On the surface, it looks as though the principal message of this study is that having sex reduces the incidence of heart attack and stroke and lets you live longer. In fact, just the opposite is true: Being healthy allows you to have as much sex as you want.”

This statement is equally true of both women and men. Your sexual health and overall health are intimately connected to each other.

A poor diet is a major contributor to heart disease, high cholesterol, arterial plaque and high blood pressure, among other conditions, all of which inhibit blood flow to the genitals and impact both desire and arousal. So what’s key to the “sex diet”? Eat for the heart, and you’re eating for desire. One of the fundamentals of a healthy diet is nutrient density. In short, when the ratio of nutrients to calories in a food is high — as is the case with most vegetables — fat burns off and health is maximized.

In addition to eating right, regular aerobic workouts provide a healthy boost. Exercise keeps the blood flowing and the arteries producing nitric oxide. Nitric oxide is the lifeblood of sexual arousal. Men who don’t exercise are much more likely to experience bouts of ED than those who do, and women who don’t exercise are also more likely to experience arousal issues. Not only is overall blood flow heightened during aerobic exercise, but feel-good endorphins that contribute to relaxation and sexual arousal are also released. Exercise also plays a major role in generating a healthy body image and sense of confidence, which is perhaps the most powerful aphrodisiac.

So for a lifetime of good health and good sexual function, get active, choose more nutritious foods and keep having sex! Up next week: We’ll explore the connection between stress, alcohol use and sexual function.

Ian Kerner is a sex therapist, relationship counselor and New York Times best-selling author of numerous books, including the recently published “Sex Detox: A Program to Detoxify and Rejuvenate Your Love Life.” He was born and raised in New York City, where he lives with his wife, two young sons and plump Jack Russell terrier.