After each failure, ask forgiveness, pick yourself up, and try again.
We may, indeed, be sure that perfect chastity—like perfect charity—will not be attained by any merely human efforts. You must ask for God’s help. Even when you have done so, it may seem to you for a long time that no help, or less help than you need, is being given. Never mind. After each failure, ask forgiveness, pick yourself up, and try again.
Very often what God first helps us towards is not the virtue itself but just this power of always trying again. For however important chastity (or courage, or truthfulness, or any other virtue) may be, this process trains us in habits of the soul which are more important still. It cures our illusions about ourselves and teaches us to depend on God. We learn, on the one hand, that we cannot trust ourselves even in our best moments, and, on the other, that we need not despair even in our worst, for our failures are forgiven.
This is an excerpt from Mere Christianity by C.S. Lewis