I’ve often found that something bad will continue to repeat itself until you learn your lesson from it.
Whether it’s a bad habit, a bad situation, a bad person in your life, or a bad environment.
If you continue to accept it and do nothing, you can’t expect anything to change or for the problem to go away.
Once you’ve learnt your lesson from it, you’ll find a way for it not to repeat itself.