Chapter Summary 5.1 Making Decisions in Code The types of program control are sequence, selection, and repetition. The IF…THEN and IF…THEN…ELSE statements are used to construct decisions. Comparison operators such as equals, greater than, and less than are used to evaluate a condition. A condition is an expression that can be evaluated to true or false only and is sometimes called a Boolean expression. 5.2 Building Boolean Expressions Boolean expressions can be easily identified by looking at the algorithm for a project. Using the AND and OR operators, a single Boolean expression can be constructed in a way that it tests for multiple conditions and provides several outcomes. When the AND operator is used to construct a condition, both parts of the condition must be true for the overall condition to be true. When the OR operator is used to construct a condition, either part of the condition can be true and the overall condition will be true. 5.3 Coding Decisions The basic decision statement is IF…THEN, and it provides for an outcome when the condition is true. The IF…THEN…ELSE statement provides for one outcome when the condition is true and another outcome if the condition is false. Error-checking is a programming technique for verifying correct user input. Nesting is a technique in which one section of code is contained within another section of code. Multiple levels of nesting can be used as there is no limit to how many statements can be nested. Check Your Computer Science IQ Now that you have finished this chapter, see what you know about computer science by taking the chapter posttest. The posttest is available at www.g-wlearning.com. 120 Introduction to Computer Science: Coding Copyright Goodheart-Willcox Co., Inc.
Previous Page Next Page