Chapter 3. Conditionals and Boolean logic

 

This chapter covers

  • Representing rules and facts in a program
  • How programs can make decisions
  • Running code conditionally based on comparisons

Although you may have never thought about it before, almost every computer program you’ve used in your life reacts and makes decisions. Any program you run will execute different sections of code depending on what you type and click, what your files contain, and even what files on other computers contain. Calculator programs are no different, and most programs you’ll want to write will need to have rules and the ability to make decisions. You’ve already seen a quadratic equation solver, QUAD, that displayed a warning about imaginary roots only if it determined that it would encounter imaginary roots. You also saw the GUESS guessing game’s decision making in deciding whether to reloop (on an incorrect guess) or end the game (on a correct guess).

3.1. Introduction to comparisons

 
 
 

3.2. Conditional statements

 
 

3.3. Boolean logic

 
 

3.4. Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest