Before buying any stock with the intention of holding it forever, it's essential to ensure that the company has the tools to survive and thrive over long periods. Some of these tools include a solid position in a market that offers goods or services that aren't likely to go out of style, a competitive advantage, and plenty of room to grow.

Let's look at two stocks that fit those criteria quite well: Intuitive Surgical (ISRG 0.77%) and Microsoft (MSFT 0.92%). Here's why shares of both companies are worth holding onto for good.

1. Intuitive Surgical

Intuitive Surgical is known for its da Vinci Surgical System, a leading robotic-assisted surgery (RAS) device that allows physicians to perform minimally invasive surgery. The da Vinci system can be used in various surgery types, from general surgeries to urology-related ones.

The advantage here is that unlike open surgery -- which requires an incision large enough for surgeons to access the organs involved -- the da Vinci system can get the job done with a few small incisions and tiny, versatile tools that highly trained physicians can manipulate with accuracy. Intuitive Surgical is the runaway leader in this field; it held an 80% market share as of 2020.

The company generally records solid and growing revenue and earnings, although the pandemic has slowed down its progress. In 2022, Intuitive's revenue increased by 9% year over year to $6.2 billion, while its earnings per share (EPS) dropped to $3.65, down from $4.66 in 2021.

Intuitive Surgical's procedure volume has been fluctuating due to COVID-19, but the company makes much of its money by selling instruments and accessories that pair up with its crown jewel. So beyond the dynamics of the past three years, the important question is whether Intuitive Surgical's procedure volume can remain northbound over the long run.

Here are several reasons why the answer is a resounding yes. First, demographic changes will play a role; the world's population is aging, and older adults typically have a greater need for surgical interventions. Second, minimally invasive procedures usually lead to better patient outcomes, including less scarring, faster recovery times, and shorter stays; these kinds of surgeries will likely continue to rise in popularity.

Third, the da Vinci system's installed base is large and growing. It was 7,544 as of the end of 2022, an increase of 12% year over year. This factor also highlights Intuitive Surgical's moat: These devices are expensive both in price (between $0.5 million and $2.5 million) and in the time it takes to train physicians to use them. Thus, Intuitive Surgical benefits from high switching costs -- just one more reason to bet on it to deliver outsized returns for a long time.

2. Microsoft

Microsoft is practically synonymous with computer operating systems. Although the tech giant has some notable competitors, it largely built its brand name around this business. With computers such an integral part of the modern world, Microsoft won't go anywhere anytime soon.

Beyond its operating systems, it offers a suite of valuable productivity tools that individuals and institutions of all types (including for-profit and non-profit organizations, universities, and more) use daily. Even with the move toward remote work, Microsoft's products -- such as Teams, which rose in popularity during the pandemic -- are valuable for businesses.

Another aspect of the company's operations critical to its future is its cloud business. Here too, Microsoft is a leader. It provides cloud-based services to other companies, allowing them to boost the efficiency of their operations. Its cloud computing arm, Azure, has been one of the fastest-growing segments of the company, even as the rest of its business has encountered some headwinds, mainly related to macroeconomic factors.

In the second quarter of its fiscal 2023, which ended Dec. 31, Microsoft's total revenue increased by just 2% year over year to $52.7 billion. However, Azure's revenue jumped by 31% year over year. The company's EPS was $2.20, decreasing by 11% from the year-ago quarter.

With a predicted compound annual growth rate of 14.1% through 2030, there's a solid opportunity for Microsoft in cloud computing. Nor will this industry have stopped expanding by then. Given the growing importance of the cloud, we can expect this market to remain northbound well beyond the next few years, during which we can reasonably estimate how fast it will grow.

The cloud business also benefits from high switching costs, since migrating from one provider to another is not an easy (or cheap) task. Microsoft's productivity tools arguably benefit from the same dynamic. Plus, Microsoft is pursuing other lucrative opportunities in artificial intelligence.

All of these efforts only build on Microsoft's valuable brand name, one of the most powerful and recognizable in the world. The tech giant has already made its longtime investors plenty of money. But even with its market capitalization of $1.9 trillion, there are plenty of market-beating years ahead for Microsoft.