Another (better option) is buy the ticket before you get on the train.
Simples!
This is true. However, if the company truly wishes to put out the message that tickets must be purchased before boarding, they have to stop selling tickets on board trains. This would conflict with their interest in collecting revenue from passengers who had no opportunity to purchase before boarding. Here in South London where there are no guards, the locals know that it's compulsory to purchase before boarding - there is no grey area, middle ground or mixed message. People still chance it based on the probability of being caught however.