Sams Teach Yourself C++ in 21 Days

(singke) #1

DAY 7


WEEK 1

7 More on Program Flow

Programs accomplish most of their work by branching and looping. On Day 4,
“Creating Expressions and Statements,” you learned how to branch your pro-
gram using the ifstatement.
Today, you will learn


  • What loops are and how they are used

  • How to build various loops

  • An alternative to deeply nested if...elsestatements


Looping ................................................................................................................


Many programming problems are solved by repeatedly acting on the same data.
Two ways to do this are recursion (discussed on Day 5, “Organizing into
Functions”) and iteration. Iteration means doing the same thing again and
again. The principal method of iteration is the loop.
Free download pdf