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.

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 War>th tondit*0*1

The computer will take this path f the ^ branch Condition is true—hat is, 9uess is equal to "5-

y^ ^puterwill take this ?aiU

The false path.

'S, guess" is something other than

Was this article helpful?

0 0

Post a comment