You’ll create more interesting games by writing programs that execute, skip, or repeat sections of code based on some condition. You’ll learn how to generate random numbers to add some unpredictability to your games. And you’ll learn about the Game Loop—a fundamental way to organize your games to keep the action going.
So far, the programs you’ve seen have been linear—each statement executes, in order, from top to bottom. However, to create interesting games, you need to write programs that execute (or skip) sections of code based on some condition. That’s the main topic of this chapter. Specifically, you’ll learn to:
if
statements to branch to sections of codeswitch
statements to select a section of code to executewhile
and do
loops to repeat sections of code