While sexual problems can't be prevented, dealing with the underlying causes of the dysfunction can help you better understand and cope with the problem when it happens. There are some things you can do to help maintain good sexual function:
Follow your doctor's treatment plan for any health conditions.
Limit your alcohol intake.
Quit smoking.
Deal with any emotional or psychological issues such as stress, depression, and anxiety. Get treatment as needed.
Increase communication with your partner.