It's very important that we count the cost of sexual immorality before temptation hits. That's the time for clear thinking. Temptation clouds our judgment. That's why we pray "keep us from temptation." Avoiding the fog by steering around it is much better than trying to navigate through it.
Years ago, as a way to keep his head clear, Randy Alcorn created a list of the ways he would bring destruction into his life and others' lives were he to give in to sexual immorality. A few months ago he posted it on his blog. It's worth reading and adapting and reviewing regularly.
Most battles are won in the planning and preparation stages. The same is true for the fight for purity.