Basically if you want to not lose money gambling you need to either never gamble, or stop gambling once you have won more than what you have gambled so far.
Unfortunately, our brains are wired in a way that if you've took some action and got desired result (positive feedback loop), you'll feel the urge to do it again. So if someone had the discipline to stop betting in the right time and walked away with profit - they're likely to return and try to repeat that success.
Gambling perfectly exploits psychological flaws.