Introduction
Before writing an application to solve a problem, it is essential to have a thorough understanding of the problem and a carefully planned approach to solving it. When writing an application, it is also essential to understand the types of building blocks that are available and to employ proven application-construction techniques. In this chapter and in Chapter 6, Control Statements: Part 2, we discuss these issues in our presentation of the theory and principles of structured programming. The concepts presented here are crucial to building classes and manipulating objects.
In this chapter, we introduce C#'s if, if...else and while control statements, three of the building blocks that allow you to specify the logic required for methods to perform their tasks. We devote a portion of the chapter (and Chapters 6 and 8) to further developing the GradeBook class introduced in Chapter 4. In particular, we add a method 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 compound assignment operators and explore its increment and decrement operators. These additional operators abbreviate and simplify many statements. Finally, we present an overview of C#'s simple types.