O'Reilly logo

Sams Teach Yourself C++ in One Hour a Day, Sixth Edition by Bradley Jones, Siddhartha Rao, Jesse Liberty

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

Chapter 7. Controlling Program Flow

Programs accomplish most of their work by branching and looping. In Lesson 5, “Working with Expressions, Statements, and Operators,” you learned how to branch your program using the if statement.

In this lesson, you will learn

  • What loops are and how they are used

  • How to build various loops

  • An alternative to deeply nested if...else statements

Programming Loops

Many programming problems are solved by repeatedly acting on the same data. Two ways to do this are recursion (discussed in Lesson 6, “Organizing Code with Functions”) and iteration. Iteration means doing the same thing again and again. The principal method of iteration is the loop.

The Roots of Looping: goto

In the primitive days of early computer science, programs ...

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