Chapter 18. Conditional Execution

Table of Contents

18.. Motivation
18.. Design vs. Implementation
18.. Boolean Expressions
Boolean Constants
Relational Expressions
Practice
18.. If Statements
C If Statements
Fortran If Statements
Additional Use Cases
Nesting If Statements
Practice Break
Practice
18.. Switch, Select-Case
Practice
18.. Code Quality
18.. Performance
18.. Practice Break Solutions
18.. Code Examples

Motivation

Computers are much more useful when they can make decisions. Most calculations cannot proceed very far without reaching some sort of crossroad, where a decision must be made about what to do next. Very few programs perform a sequence of calculations with no branches. In this chapter, we will explore ways to design and implement decision-making in our algorithms and code.