Is it legal to treat yourself and prescribe yourself medication if you are a doctor?

I'm not sure of international laws about the subject, yet I believe that medication must be prescribed for a third party. So even if you are a doctor you can't prescribe yourself medication