Have you ever been so stressed you start to feel a little panicky? Maybe your heart feels like it’s going to beat out of your chest. Your palms might get sweaty. You might even feel a sense of impending doom like something terrible is going to happen.

Some people experience anxiety that’s so severe it manifests as panic attacks. If you’ve ever had a panic attack, you know how awful they can make you feel. And this type of stress response isn’t good for your body (or your risk for cognitive decline).

Prolonged stress is associated with an almost doubled risk for cognitive decline. Chronic stress also increases the risk of cardiovascular disease, another risk factor for dementia. Stress can even prevent your body from healing after trauma, illness, or injury.

It’s clear that stress isn’t good for you, but it’s not always so easy to reduce your stress. If you need your paycheck, it might not be an option to leave your stressful job. Your commute might be unavoidable. Your mother-in-law might need to live with you. So, what can you do when you can’t just walk away from the stressors in your life?

Work out.

Stress contributes to changes in the immune system. Thankfully, research suggests exercise may protect the immune system from the harmful effects of stress. A better immune system equals better cognitive health, since your immune system can protect your brain from inflammatory changes that can lead to dementia. Exercise can also help curb the anxiety and depression that are often linked with prolonged stress.

Working out when you feel stressed can help alleviate anxiety, but it’s hard to start an exercise program when you’re in the throws of it. Starting an exercise plan before you get stressed will help you better manage stress when it arises. Think of it as preventative medicine.