Lesson 7Controlling Program Flow
In this lesson, we are going to begin to look at how we can control the flow of a program. Specifically, we look at how we can make decisions and change the flow based on those decisions. To do that, you will be introduced to conditional statements and boolean expressions.
WHAT CAN OUR CODE DO?
So far, our programs have simply executed from beginning to end, one statement after another. We've added some code that allows us to get input from the user, but even with that, our code executes in a straight line—the same way every time. You would think there has to be more that can be done than this, and you'd be right. There is more but, surprisingly, not too much more. Here is what we can do in code:
- Execute statements one after another in a straight line
- Make decisions to execute one block of code instead of another based on some criteria
- Repeat a set of statements a certain number of times based on some criteria
That's it—there is no more. All programs are built from these building blocks. We've already covered creating code in straight lines. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access