The majority of Torah commandments more often focuses on actions and deeds, not thoughts.  Yet there are certain commandments that focus on our thoughts and how we must guard them and shape them.  (Chovos Halevavos wrote his Sefer by that name because he felt these mitzvos were ignored.)

Our Gemara on Amud Beis tells us:

״וְנִשְׁמַרְתָּ מִכֹּל דָּבָר רָע״, מִכָּאן אָמַר רַבִּי פִּנְחָס בֶּן יָאִיר: אַל יְהַרְהֵר אָדָם בַּיּוֹם וְיָבֹא לִידֵי טוּמְאָה בַּלַּיְלָה.

Rabbi Pineḥas ben Yair taught: “Then you shall keep yourself from every evil thing” (Devarim 23:10) from here Rabbi Pineḥas ben Yair said: A person should not think impure thoughts by day and thereby come by night to the impurity of an emission.

Actually, the Gemara Yoma (29a) tells us:

הִרְהוּרֵי עֲבֵירָה קָשׁוּ מֵעֲבֵירָה, וְסִימָנָיךְ: רֵיחָא דְבִישְׂרָא. שִׁילְהֵי דְקַיְיטָא קְשֵׁי מִקַּיְיטָא, וְסִימָנָיךְ: תַּנּוּרָא שְׁגִירָא.

Thoughts of transgression are worse than transgression itself, and your mnemonic is the odor of meat. The smell of roasting meat is more appetizing than actually eating the meat. The heat of the end of summer is more oppressive than the heat of the summer itself, and your mnemonic is a heated oven. After an oven has been heated several times in the course of a day, lighting it again, even slightly, will produce powerful heat. So too, at the end of the summer, since everything is hot, the heat is more oppressive.

Why is it so, that the thoughts of sin are worse than the sin itself?  The gemara seems to imply from its oven-in-the-summer metaphor, that by thinking sinful thoughts and dwelling on them, the oven becomes hotter and cooks faster.  Therefore, in essence, the actual sins will be worse because the pump was primed.

Rashi (ibid) explains that the thoughts are worse because the object of desire is not fulfilled.  Thus, you get the punishment without even the benefit of the full satisfaction. 

Ralbag (Vayikra 6:1) says the thoughts are worse because we minimize them and rationalize them, since after all, no deed was done.  The problem is, the Ralbag says, the thoughts LEAD the person to sin.

Reishis Chokmah (Shaar Hakedusha 16) and the Rambam (Moreh Nevukim 3:18) and Ramban Iggeres Hakodesh (“Umekan”) all say more or less the same idea.  A person’s soul thrives on attachment to God and holiness.  If a person sins, true he or she has disrupted that holiness, but it is for a moment.  But if a person dwells on thoughts of sin, then the soul is immersed in sin and remains unattached to God for a far lengthier time.  

Think of it this way:  A person can spend their entire married life technically faithful to their spouse, but not living with intimacy, love or respect.  No one can say he or she cheated, nor can we say cheating is better.  Yet and yet…imagine a person who lived an entire life with intimacy, love and respect for their spouse, and during a moment of weakness committed adultery.  Yes, this person has technically transgressed by far to a great degree.  But, I ask, who has the better life and the better relationship?

In addiction psychology, the loss of sobriety is often merely the final stage in a process of loss of sober thinking that may have begun days or weeks earlier. Many addicts go into “cruising mode”, in which they are preoccupied and obsessing over how to get their next fix, and the titillation of that experience can be as addictive as the substance or process that hooks them.