O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Nesting Loops

In Chapter 6, you read about a technique called nesting, where you were able to put conditions within conditions as a substitute for using multiple conditions, logically combined together. Loops can also be nested, but you don’t nest to avoid nested conditions. You nest loops because you need to do additional repetitive work within an outer loop.

So you have a nest of loops where the outermost loop will be executed first (one iteration), and then the inside loop will be executed until it reaches a conclusion. Control is then returned to the outer loop. In this way, the inner loop is executed n times for every pass of the outer loop.

Figure 7.1 depicts loop nesting in a diagram format.

Figure 7.1. Loop Nesting

If you execute ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required