O'Reilly logo

C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart 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

3 The Handy, All-Purpose “for” Statement

Some tasks are so common that C++ provides special syntax just to represent them with fewer keystrokes. An example is the increment operator (++) introduced in Chapter 2. Because adding 1 to a variable is so common, C++ provides this operator to add 1 even though you could get away without it.

    n++;  // Add 1 to n.

Another case is the for statement. Its only purpose in life is to make certain kinds of while loops more concise. But this turns out to be so useful that programmers come to rely on it heavily. I use it throughout the rest of this book.

You’ll find that once you use it a few times the for statement becomes second nature. Unfortunately, it looks strange the first time you see it. And to be ...

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