Home > Articles > Programming > C/C++

C++ for Programmers: Control Statements: Part 1

  • Print
  • + Share This
Get an introduction to C++'s if, if...else and while statements, three of the building blocks that allow you to specify the logic required for member functions to perform their tasks. Also learn to use while repetition statement, counter-controlled repetition and sentinel-controlled repetition, and the increment, decrement and assignment operators.
This chapter is from the book

This chapter is from the book

4.1 Introduction

In this chapter, we introduce C++'s if, if...else and while statements, three of the building blocks that allow you to specify the logic required for member functions to perform their tasks. We devote a portion of this chapter (and Chapters 5 and 7) to further developing the GradeBook class introduced in Chapter 3. In particular, we add a member function to the GradeBook class that uses control statements to calculate the average of a set of student grades. Another example demonstrates additional ways to combine control statements to solve a similar problem. We introduce C++'s assignment operators and explore C++'s increment and decrement operators. These additional operators abbreviate and simplify many program statements.

  • + Share This
  • 🔖 Save To Your Account