LUSTFUL THOUGHTS [Ervah:thoughts]
Gemara
Rav Nachman: Thoughts of sin are worse than sin.
Chulin 37b: Yechezkeil said about himself "I did not Metamei my soul", i.e. I did see Keri at night due to thoughts of women during the day.
Question: Why is this so praiseworthy? It is forbidden to do so!
Answer (Tosfos DH she'Lo): Lustful thoughts are one of three things that most people transgress every day.
Bava Basra 164b - Rav Amram: There are three transgressions that (most) people transgress every day - thoughts of (sexual) transgression, (lack of) concentration in prayer, and (dust of) Lashon ha'Ra.
Avodah Zarah 20b: "V'Nishmarta mi'Kol Davar Ra" - do not have thoughts during the day, for it causes Tum'ah at night
R. Gamliel was in Har ha'Bayis, and he saw a beautiful Nochris. He said 'Hashem, how great are Your works!'
Question: It is forbidden to look at women!
(Beraisa): "V'Nishmarta mi'Kol Davar Ra" - one may not look at a beautiful woman even if she is single, or at a married woman even if she is ugly;
One may not look at a woman's colored clothing, nor at animals or birds mating, even if they fill his field of vision.
Answer: R. Gamliel inadvertently saw her when he turned a corner. He did not know in advance to close his eyes.
Rishonim
Rambam (Hilchos Isurei Bi'ah 21:1-3): One may look at a single girl, whether or not she is a virgin, to see if he wants to marry her. This is proper, but he should not look lustfully.
Objection (Ra'avad): Chachamim taught that a Chacham should take an Am ha'Aretz with him when going to be Mekadesh a girl (to ensure that the same girl will be given at the Chupah). This shows that a Chacham does not look at her!
Answer (Magid Mishnah): A Chacham looks once, but this will not suffice to recognize her later because he is not so proficient about the appearance of women.
Rambam (ibid. 19-21): It is forbidden for a man to intentionally cause Kishuy or to bring himself to lustful thoughts. Rather, if such thoughts come he should divert his mind from folly to thoughts of Torah.
One may not look at women hanging up laundry. It is even forbidden to look at colored clothing of a woman he recognizes lest he come to have thoughts.
Rashi (DH Hirhurei): Thoughts of sin are worse than sin, i.e. they weaken the body more than the act itself.
Anaf Yosef (DH Hirhurei): Chachamim consider thoughts to be beyond a person's control. This applies only to the initial thought. One must divert his mind; if not, he will dote on the matter. Also, if one would properly fill his mind with Torah and work, he would not have the initial thought. Once a person decides to sin, he will dote on it until doing the act.
The thoughts are worse than the act because they are at every moment. When the heart is a Mishkan for the Satan, Kedushah departs. Alternatively, it is harder to refrain from lustful thoughts (when the Yetzer ha'Ra is ravenous) more than from the act (after which it is sated).
Poskim
Shulchan Aruch (EH 21:1): One must distance himself very very much from women.
Beis Shmuel (1): Even though only a minority of people sin with Arayos, Chachamim warned excessively about it for one who is habituated to it finds it very hard to refrain.
Beis Yosef (DH Kasuv b'Orchos, citing R. Yonah): Looking at a single woman is forbidden from Kesuvim - "Bris Korati l'Einai u'Mah Esbonen Al Besulah". Thinking even about a single woman is worse than touching her; it is forbidden mid'Oraisa! "V'Nishmarta mi'Kol Davar Ra" - do not have thoughts during the day, for they lead to Tum'ah at night.
Beis Shmuel (2): The Rambam holds that looking at a married woman is forbidden only mid'Rabanan. All agree that looking at a single girl is forbidden from Kesuvim, and that Hirhur even about a single girl is forbidden mid'Oraisa.
Pri Megadim (Sof Petichah Kelalis, 5:34): Perhaps the Isur of Hirhurim is mid'Rabanan.
Shulchan Aruch (ibid. 4): One may look at Ishto (his wife even when she is) Nidah, even if it is pleasurable. Because she will be permitted later, he will not sin.
Source (Beis Yosef DH v'Chen): Shabbos 64b permits a Nidah to adorn himself lest she become repulsive to her husband. We infer that he may look at her.
Shulchan Aruch (ibid. 5): One may not be served by a woman or girl, whether a slave or free, lest he have thoughts. This refers to washing his hands, feet and face, or even pouring water for this without touching him, spreading the sheet in front of him, and mixing his drink.
Shulchan Aruch (25:1): One should conduct with exceeding Kedushah, lest one stumble with Ervah. One should beware of seclusion with women, frivolity, intoxication, and lewd speech. One should not dwell without a wife. This causes great Taharah. One should divert his mind to Torah and Chachmah; thoughts of Arayos are found only in a mind empty of Chachmah.
Shulchan Aruch (OC 75:1): One who faces an exposed (square) Tefach (in a place that is normally covered) of a woman may not say Shma.
Question: At all times it is forbidden to look even at the pinky!
Answer (Bach DH Tefach): At other times it is forbidden only if he intends to look, for then he gets pleasure.
Question: This implies that one may see areas normally exposed without intent for pleasure. If so, when the Gemara asked about the episode with R. Gamliel, why didn't it answer that he did not intend for pleasure?
Answer (Igros Moshe OC 1:40): R. Gamliel exclaimed 'Hashem, how great are Your works', which shows that he got pleasure. Therefore, the Gemara needed to answer that he turned a corner and did not have time to close his eyes. One must always strive to avoid looking at women, lest it be pleasurable. When walking in the street one should try to look down unless this would make him prone to injury.
Shulchan Aruch (OC 85:2): One may not think about Torah in a bathroom or bathhouse. One may speak a matter of Kedushah if needed to prevent transgression.
Mishnah Berurah (13): Similarly, if one has lustful thoughts there he may think of Torah to prevent this transgression. Torah saves from evil thoughts.
Shulchan Aruch (OC 240:1): One should not have relations too frequently with his wife...One may have relations with her to fence his Yetzer ha'Ra if it is overpowering him with lust for sin.
Rema: Also for this he will be rewarded.
Shulchan Aruch (ibid.): It would be better if he could overcome his Yetzer, for if one starves his Ever it will be satiated, if he satiates it, it will crave more. If one does not need to, but arouses his lust to fulfill it, this is the counsel of the Yetzer ha'Ra. From Heter it will lead him to Isur. Regarding this, Chachamim said that one who intentionally causes Kishuy should be excommunicated.
Shulchan Aruch (YD 195:7): When one's wife is Nidah, he may not look at her heel or parts that are normally covered. He may look at places that are normally exposed even if it is pleasurable.
Beis Yosef (DH u'Mah she'Chosav Aval): A Chasan who has not yet had relations with his wife may not be secluded with her when she is Nidah, for his Yetzer is great. If he already had relations with her it is permitted, for his Yetzer ha'Ra does not overpower him.