Vince Gironda once famously said that bodybuilding is 85% nutrition. Hundreds of people who hit the gym regularly and make no progress are living proof that you cannot out-train a stupid diet.
Let’s keep this simple :
If you want to lose weight you have to burn more calories than you consume and vice versa. Either you create a calorie deficit to lose weight or a calorie surplus to gain.
The number of calories you burn in a day is largely your BMR (Basal Metabolic Rate) plus physical activities performed.
The number of calories you consume is the quantity of the 3 main macronutrients proteins, fats & carbs. Protein and Carbs both contain 4 calories per gram but fat contains 9 calories per gram consumed.
You can only succeed in you chosen goal if you know the above equation (even a rough idea will do) else you’re just killing time.
If you need further evidence, when you exercise, you use muscle. This helps build muscle mass, and muscle tissue burns more calories -- even when you're at rest -- than body fat. According to a Wharton study, 10 pounds of muscle would burn 50 calories in a day spent at rest, while 10 pounds of fat would burn 20 calories. Your BMR, hence your daily calorie burn, will be higher the more muscle mass you have than not.
So, it’s a self-serving proposition. More muscle means more calorie burn means it’s easier to stay in shape