You are either the one doing the farting in class, or you can smell it and you know someone else is. It sucks, but unfortunately, there's not much you can do in the actual moment (except for maybe go to the bathroom), but there are things you can do in advance so it won't happen in the future. 

You might be wondering why you even fart. Some reasons could be the food you are eating, maybe you're lactose intolerant, or maybe you swallowed a lot of air. Luckily, there are things you can do that will solve all of these problems. 

Don't drink carbonated beverages

beer
Sammy Mintzer

Drinking a soda here or there isn't going to make a huge difference, but it probably isn't the best idea to drink a soda right before class. It fills your intestines with air, which causes you to fart. Beer is also a carbonated beverage, so I would avoid drinking beer on the regular because this could help you in the long run.

Eat slowly 

coffee
Katherine Baker

When you eat too quickly, it affects digestion and causes you to fart. You're more likely to swallow air with your food, which clogs up your intestines. This air will need to be released and will come out as a fart. 

Don't chew gum

candy
Rachel Weitzman

When you chew gum, you end up swallowing more air than you should, which is going to leave from one end or the other. Both are out of your control. 

Quit smoking

Like chewing gum, smoking causes you to swallow air. Even if you only have that one casual drunk cigarette, you might want to quit if you're trying to get rid of your farting problem (and maybe for other reasons as well). 

Avoid sugar

cranberry, cake, berry, pastry, jam, cream, chocolate, sweet
Elena Besser

Sugar is broken down by the bacteria in your gut pretty quickly, which causes a greater gas release when your food is digested. If you're one of those people who seriously needs dessert, try one of these sugar-free desserts that taste like the real thing. 

Slow down on alcohol

tea, juice, alcohol, liquor, beer, cocktail, ice
Daniel Schuleman

Alcohol tends to have a lot of sugar, which you now know makes people fart. When you drink, you also give up some control over your body, which can make it harder to control your farts.

Eat less starch

cookie, wheat, nut, sweet, cereal
Hannah Linn

Starches release intestinal gas when digested, which means you'll fart. If you really want to eat a starch, rice is one of the better ones because it's easy for your body to digest.