Why? Why do I. Keep doing this?

I keep saying I will lose weight I will lose wdight I will lose weight and I end up losing 2 pounds and gain it back and quit. How do i actually lose the weight and not eat bad food and starve? I did that 2 years ago and lost 36 pounds. 2 years later I gained it all back. I’m obese and I’m 17 and school is starting In 2 months. I’m ugly and fat. My boyfriend lost feelings for me. Everytime I try to lose weight I lose it then I don’t focus and eat junk food. How do I control myself and not eat it it’s so good!! How do I be for good this time an stick up and say no and maintain when I lose the weight? How do I lose weight?