Self-satisfaction which is called masturbation is a cardinal sin and haram [i] and there is a heavy punishment for that. The best way to avoid masturbation is to get married (permanently or temporarily) under special conditions stipulated in religious articles. If marriage is not possible one should avoid masturbation by exercising, fasting, and filling his spare times in order to keep people and society safe from mental, spiritual and physical damages of this action.
Having sexual relation with a woman other than your wife (permanent or temporary) is haram in any way. Although there are different levels and punishments for this sin itself, we can not consider this as green light to commit one evil and avoid another because it is less sinful than the other one.
[i] . This sin has been considered equal to adultery in anecdotes. Vasayel Al Shiite, vol. 20, page 352.
Masturbate or self – satisfaction that has been referred to as masturbation in religious texts, means doing something to discharge the sperm from the body. This can be done by touching your body, watching sexual scenes (pictures, movies, …) or reading sexual contents and books (stories, novels,…) or listening to sexual materials (tape, telephone conversation,…) or thinking about sexual matters in order to discharge the sperms. In either ways, this is haram and considered as cardinal sin.
The best way to avoid masturbation and self – satisfaction is legal marriage (permanently or temporarily) under special conditions stipulated in practical article. If marriage is not possible, one can use the following recommendations:
1 – Decide firmly to avoid masturbation
2 – Avoid watching any type of pictures and movies sexual in nature.
3 – Be careful when you choose your friend. Do not choose the type of people who enforce you to do this. Also, avoid making friend illegally with opposite sex.
4 – Avoid dreaming and try to make yourself busy with good things such as reading books (non-sexual ones), heavy exercise, etc. Moreover, remember that idleness can lead you to anything.
5 – If possible, try not to be alone anywhere.
6 – Fasting can be quite helpful in controlling your internal desires and strengthening your will.
If you cannot fast, do not eat a lot or at least do not over load your stomach when you want to sleep.
7 – Do not eat food items, which are sexual arousing like banana, chocolate, fig, date, onion, pepper, egg, red meat, oily foods, etc.
8 – Keep your urinary bladder empty at all times.
9 – Read some books before going to sleep at night and never sleep on your front.
 . In some cases this may bear religious limitations and in some other cases it bears punishment.