I have certainly done a few rounds with mental loops in my time. At different times of my life, I have obsessed on...
- death and its inescapability
- afterlife religious possibilities
- what I should be doing to be a better person, have more money, etc.
- the seeming pointlessness of life in general
- am I doing the right thing
Certainly all of these topics should be considered and thoughts in general are necessary and in no way bad. The problem occurs when you get these circular loops that you can't control. I think we often try to think our way out of the process when it is thinking itself that gets you in the loop. It's like curing alcoholism with beer.
As is so often the case the answer is to get out of the worries about the past and the future and be fully in the present. You can get that advice anywhere, but how do you do it? The answer is through the body. The body can rescue your mind.
First, it is important to understand how the body reflects the mind and vice-versa. When you are locked in a mental loop of regret or worry, your body will clench up and your breathing will be shallow. Lock up your body and you can find yourself going into a mental loop. Also, your attention is focused inward giving energy to the mental loop.
To stop it, you have to get out of your head and focus outward. Start looking and listening to what is around you and let your body relax. Breathe deeply. Feel. The instant your body relaxes, your mind will get off the treadmill.
I used to have terrible insomnia, I found that it was caused by three things. Caffeine, insufficient physical activity and/or mental loops. I would sit in bed and worry and I couldn't sleep. Relaxing the body and focusing outward, pretty much solved it for me. I still forget occasionally, because knowing something doesn't mean you will do it all the time.