Page 49 -
P. 49
fork in the road
Branches are code intersections
Driving down a street is easy. You need to make a decision only when
you get to an intersection. It’s the same for your program. When a
program has a list of commands, it can blindly execute them one after
another. But sometimes, your program needs to make a decision. Does
it run this piece of code or that piece of code?
These decision points are called branches, and they are the road
intersections in your code.
Branches are like road
intersections.
Your program makes a decision using a branch condition. A branch
condition has the value true or false. If the branch condition is true, it
runs the code on the true branch. And if the branch condition is false, it
runs the code on the false branch.
The computer will take this path if the
The branch branch condition is true−that is, “guess"
condition. is equal to 5.
The true path..
guess==5?
The false path.
The computer will take this path if
the branch condition is false−that
is, “guess" is something other than 5.
14 Chapter 1