Stock market downturns are never easy, especially when they turn into bear markets. The Nasdaq is down roughly 25% since the beginning of the year, and the S&P 500 has been hovering around bear market territory for months.

When stock prices are falling, it's tempting to either pull your money out of the market or stop investing for the time being. However, while it may sound counterintuitive, continuing to invest during a bear market is a fantastic opportunity to build wealth.

Why I'm still investing as prices drop

The primary reason I'm continuing to invest during a bear market -- and will continue to invest, regardless of how far prices fall -- is that it's a perfect opportunity to buy at a discount.

Stock prices are lower than they've been in months, and even the most expensive stocks are significantly more affordable than they were six months or a year ago. The market is essentially on sale right now, and there's never been a better time to invest for a bargain.

In addition, buying when the market is down can set you up for substantial gains. No downturn lasts forever (in fact, the average bear market lasts roughly 10 months), so it's only a matter of time before the market recovers.

^SPX Chart

^SPX data by YCharts

Of course, nobody knows for certain how long this slump will last. But stock prices will rebound eventually. If you buy when prices are at their lowest, you could see a significant upswing.

How to earn as much as possible in the stock market

The key to maximizing your earnings is to choose the right stocks and hold for the long term.

Not all stocks will be able to survive a bear market -- especially if a recession is looming. But strong companies have a much better chance of pulling through periods of volatility.

Keep in mind that even the best stocks will likely take a hit in the short term, so if your portfolio continues to drop immediately after you invest, that's normal. But healthy companies are far more likely to rebound from a market downturn and see positive average returns over time.

So when researching stocks, focus on companies that have solid underlying business fundamentals. This will include everything from healthy financials to a competent leadership team to a competitive advantage in its industry.

By investing in these types of companies and holding your stocks for at least a few years, you're far more likely to make money in the stock market.

The future of the stock market

Nobody can predict exactly how the market will perform in the short term. Stock prices could fall further before they bounce back, and it could potentially take months or even years for the market to fully recover.

However, over the long term, it's extremely likely that the market will experience positive average returns. By investing when prices are lower and holding those stocks for years, you can maximize your returns and generate long-term wealth.