The mind is a hard thing to train but it can be trained to avoid the temptations of this world..it just takes time and dedication!
The mind can often wonder off into it's own world without warning and when that happens it's best to take a step back and take a walk away from it all for a while..I take walks very often because it helps me to remember why I'm here and what I need to be thinking about, as Christians I think that's one of the most tricky things to learn to control..because there are so many..shall we say "resources" that causes us to sometimes wonder off into thoughts that we shouldn't be thinking in the first place!
Don't worry though..because we all go through this at some point in our lives and we all have moments when we go back to those impure thoughts! I'm here to tell you that God can help you through that problem! God can help you to train your mind!
"I appeal to you therefore, brothers, by the mercies of God, to present your bodies as a living sacrifice, holy and acceptable to God, which is your spiritual worship. Do not be conformed to this world, but be transformed by the renewal of your mind, that by testing you may discern what is the will of God, what is good and acceptable and perfect."
God can help you to keep your mind focused of his ways instead of keeping your mind of the things of this world! All it takes from you is the desire to change for the glory of God and God will give you the determination you'll need to get through it! Trust in him and he will help you to control your thoughts so that you can remain focused of what's important!
Besides, God has way too many things for us to do and we need to work hard to get to that place where we can keep our minds on Christ Jesus and keep the worldly things out of our minds!
God can help you with that problem..give it to him and he will help you to train your mind!
If you have trained your mind to keep it on the Godly things but you have struggled recently..I want you to know that there's forgiveness from that! God still loves you and is waiting for you to come back to him..everyone struggles with that problem so don't stress over it or think that God loves you less..because he loves us all the same and he wants to see you come back to him! Ask him for forgiveness and ask him to help you with this problem and he will!
Don't think for a second that you're on your own because you're not..God is with you and your brothers and sisters in Christ are standing with you as well! Think on the things of Christ and you can't go wrong!