Q. Kvod Harav. When someone finds himself in a compromising situation where he is likely to transgress an issur and he can’t get away, such as traveling in a packed subway or car being surrounded by people talking lashon horaa, or as you quoted in a recent question sitting next to a woman or eating something you usually avoid like cholov akum, but not when you travel, in such situations is it better to try to do a mitzvah at that time, like learning Torah, saying tehilim or in the case of questionable food, making a bracha with more kavana. You may hope that the added mitzvah will help, or the contrary is true, since it becomes a mitzvah habaa beavera, it does not have value and one may be feeding the dark fores, chas veshalom. What is the correct approach?

A. Horav Shlomo Miller’s Shlit’a opinion is that there are many variables to each particular situation, and even small changes in the case can make a great difference. Therefore, a competent Rabbi or mentor should be consulted in any such compromising or questionable situation, in order to make the right decision.
However, the Rov’s opinion is that in principle learning Torah and thinking Torah thoughts, as our Sages teach, (Sota 21a), is an inherent protection in all situations. We should emphasize, that because of the greatness and transcendence of this most important of all mitzvos, one should endeavor constantly to engage in Torah learning, even when one is not in need of protection or in a compromising situation.
The Rov added that reciting a brocho with great kavono and intention on questionable food is a different issue. Shulchan Aruch (O.H. 196: 1) rules that on a food item that is prohibited even only rabbinically, one does not recite a brocho. More so, it is even called “menaetz” or insulting and offensive, and therefore prohibited. (Bava Kamma 94a, Sanhedrin 6b).
However, on food that one abstains from, only as a “chumra” or elective stringency, a brocho must be recited when eaten permissibly, in a time of need.
(On question 1446 regarding one who is considering becoming a baal teshuva and he doesn’t yet keep Shabbos, kashrus, taharas hamishpocho etc. etc., if he should already now put on tefilin, tzitzis, daven and do other mitzvos, since the mitzvos may go to feed the klippos and the sitra acher and better wait until later we wrote;
“In principle a sinner should indeed first repent and then proceed to do mitzvos and good deeds, as the pasuk (Tehilim 34: 15 ) teaches “sur mera vease tov – depart from evil and do good.” He may also incur into: But to the wicked man Hashem said, “For what reason do you recount My statutes, and bring up My covenant on Your mouth? (Tehilim 50: 16).
Rambam (H. Teshuva 7: 7) similarly writes; How sublime is the elated Teshuva; yesterday (the sinner) was isolated from Hashem, the G-d of Israel… he would cry out, but was not answered… he would perform mitzvos, and they would be thrown back into his face, as it is written; (Yeshayahu 1: 12) When you come to appear before Me, who requested this of you, to trample My courts?
Many Cabbala and Musar sefarim do stress how nefarious and damaging could be the mitzvos that are created in a state of impurity. (see Beir Heitev O.H. 571, Shaar Hayechudim from Rav Chaim Vital, introduction to Drerech Pikudecha, et. al.)
However, they also assert that when teshuva is eventually accomplished, they all can return to the source and roots of kedusha.
Horav Shlomo Miller Shlit’a also pointed out that he is obligated at all times to comply with all mitzvos, besides “mitzva goreres mitzva – one mitzva causes and brings to others.” Eventually his Torah learning, tefilos and mitzvos will be the tools needed to guide him and encourage him back into complete teshuva”).

Rabbi A. Bartfeld as revised by Horav Shlomo Miller Shlit’a