Up to a certain point, you can do both just by exercising more and harder. A complete beginner starting from zero volume will definitely lose fat and gain muscle if they start working out, as long as they eat no more than enough to maintain their weight. The only problem is that you can only do it if you're pretty poorly trained to start with. Most people who work out seriously are well past the point where they can do both at the same time.