- 4.1 Introduction
- 4.2 Essentials of Counter-Controlled Iteration
- 4.3 for Iteration Statement
- 4.4 Examples Using the for Statement
- 4.5 Application: Summing Even Integers
- 4.6 Application: Compound-Interest Calculations
- 4.7 do... while Iteration Statement
- 4.8 switch Multiple-Selection Statement
- 4.9 C++17 Selection Statements with Initializers
- 4.10 break and continue Statements
- 4.11 Logical Operators
- 4.12 Confusing the Equality (==) and Assignment (=) Operators
- 4.13 Objects-Natural Case Study: Using the miniz-cpp Library to Write and Read ZIP files
- 4.14 C++20 Text Formatting with Field Widths and Precisions
- 4.15 Wrap-Up
4.15 Wrap-Up
In this chapter, we completed our introduction to all but one of C++’s control statements, which enable you to control the flow of execution in functions. Chapter 3 discussed if, if…else and while. Chapter 4 demonstrated for, do…while and switch. We showed C++17’s enhancements that allow you to initialize a variable in the header of an if and switch statement. You used the break statement to exit a switch statement and to terminate a loop immediately. You used a continue statement to terminate a loop’s current iteration and proceed with the loop’s next iteration. We introduced C++’s logical operators, which enable you to use more complex conditional expressions in control statements.
In the Objects-Natural case study, we used the miniz-cpp open-source library to create and read compressed ZIP archive files. Finally, we introduced more of C++20’s powerful and expressive text-formatting features. In Chapter 5, you’ll create your own custom functions.