O'Reilly logo

Exploring C++ 11, Second Edition by Ray Lischner

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

EXPLORATION 7

image

For Loops

Explorations 2 and 3 show some simple while loops. This Exploration introduces the while loop’s big brother, the for loop.

Bounded Loops

You’ve already seen while loops that read from the standard input until no more input is available. That is a classic case of an unbounded loop. Unless you know beforehand exactly what the input stream will contain, you cannot determine the loop’s bounds or limits. Sometimes you know in advance how many times the loop must run; that is, you know the bounds of the loop, making it a bounded loop. The for loop is how C++ implements a bounded loop.

Let’s start with a simple example. Listing ...

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