Warren Buffett has been a prolific investor for decades, soundly beating the markets on a consistent basis. What's noteworthy is that he hasn't generally done it by betting on big tech or emerging growth stocks in high-risk industries. His strategy centers around safety and not about taking oversized risks.

There are two Buffett rules in particular that investors would do well to always keep in mind when buying stocks. Let's look at them both.

Never lose money

This rule is so important that even his second rule is to not forget the first one. Not losing money in the stock market can seem impossible, especially in the current bear market. Even Buffett's business, Berkshire Hathaway, has lost money on its investments in the past and has even underperformed the S&P 500 in some years.

The nature of the stock market is that there will always be some risk. The key takeaway from Buffett's rule is to not take unnecessary or excessive risks and that the desire to avoid losing money should guide investors to making more calculated, strategic investment decisions, as opposed to jumping onto the latest meme stock.

Stop digging

This leads to another great Buffett quote: "The most important thing to do if you find yourself in a hole is to stop digging."

In other words, if you've taken on too much stock risk and gotten yourself into a hole (e.g., your portfolio is deep in the red), the temptation may be to take on even greater risk and swing for a 10-bagger investment that gets you out of the hole. But by doing so, you could end up with even greater losses.

By minimizing losses to begin with, investors can avoid the temptation to take on excessive risks entirely. One industry where you can find many safer stocks is healthcare.

Healthcare stocks for long-term investors

Not all industries have performed poorly during the current downturn in the markets. One segment that has bucked the trend is healthcare.

Consider healthcare giant Bristol Myers Squibb (BMY 0.80%), a top-performing stock in 2022. Year to date, the stock is up an impressive 17%, while the S&P has declined by 21%. Bristol Myers is a top drugmaker that has solid fundamentals. Last year, the company had three products that generated more than $5 billion in revenue for the business: Revlimid, Eliquis, and Opdivo. And they all reported positive year-over-year growth of at least 6%.

The healthcare company has grown, in part, via acquisitions and in 2021 reported revenue of $46 billion -- more than double its $23 billion tally in 2018. It has also posted free cash flow of at least $13 billion for two consecutive years.

Another top healthcare stock that has performed reasonably well this year is Johnson & Johnson (JNJ -0.63%). Year to date, its shares are flat, but that would still satisfy Buffett's first and second investing rules by avoiding losses.

The popular drug manufacturer and medical device company recently reported encouraging earnings numbers. Sales totaled $23.8 billion for its most recent quarter (ended in September) and rose 1.9% year over year. The business expects to generate operational sales growth, which excludes the impact of acquisitions/divestitures and translating foreign currency, of up to 7.2% this year.

These businesses are safe and are excellent examples of the types of companies to invest in if your priority is to avoid losing money. Over the past decade, Bristol Myers and Johnson & Johnson have generated total returns (which include dividends) of 190% and 213%, respectively. That's not far from the S&P 500 total returns of 223% over that time frame. And if the recent trends continue, the two healthcare stocks could continue to shrink that gap.