Chapter 19. Conditional Execution

Table of Contents

19.. Motivation
19.. Design vs. Implementation
19.. Boolean Expressions
Boolean Constants
Relational Expressions
Practice
19.. If Statements
C If Statements
Fortran If Statements
Additional Use Cases
Nesting If Statements
Practice Break
Practice
19.. Switch, Select-Case
Practice
19.. Code Quality
19.. Performance
19.. Practice Break Solutions
19.. 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.