O'Reilly logo

C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart, Third Edition by Brian Overland

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

4. The Handy, All-Purpose “for” Statement

Some tasks are so common that C++ provides special syntax just to represent them with fewer keystrokes: the increment operator (++) is one example. Because adding 1 is so common, C++ provides the increment operator to save space, although many other languages make do without it.

++n;    // Add 1 to n.

Subtraction by one is common as well, so C++ also provides the decrement operator, used in the expressions −−n and n−−.

Another example is the C++ for statement. Its only purpose is to make certain kinds of loops more concise. However, this turns out to be so useful that programmers rely on it heavily and I use it throughout the rest of this book.

You’ll find that once you use it a few times, the for statement ...

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