3. And Even More Decisions!

Building on simple decision-making structures, Chapter 2, “Decisions, Decisions,” showed how computers can do complex and interesting things, such as play a game, repeat an operation a set number of times, and perform mathematical operations.

Critical to these operations are something called control structures—a set of keywords (if, else, while) and associated grammar—that control what the program does next. These control structures, nearly all inherited from C, include just a few simple but extremely versatile keywords. This chapter introduces two more: do-while and switch.

Remember that by controlling what the program does next, you control the program! It’s that simple.

The do-while Loop

If you’ve worked through ...

Get C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.