You don't have to have sex to cure loneliness. The two may be loosely related but onenis not causal to the other.
There are plenty of partnered people having sex regularly who are extremely lonely. Many of the suicides bringing this discussion to the fore are married men having sex.