< Previous | Contents | Next >
Truth, Branching, and the Game Loop: Guess My Number
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:
n Understand truth (as C++ defines it)
n Use if statements to branch to sections of code
n Use switch statements to select a section of code to execute
n Use while and do loops to repeat sections of code
n Generate random numbers