A firm will exit a market if in the longterm its total costs are higher than its total revenue.
Work Step by Step
That is because every firm is trying to generate profit, which can be calculated as TotalRevenue-TotalCosts. If that is negative in the longterm, the firm should exit the market, because will not be profitable to operate. With this being said, there are situations where firms will stay in the market even when they are losing money. After all, sometimes the costs to leave the market exceed the losses involved in staying open.