O'Reilly logo

C Programming Absolute Beginner’s Guide, Third Edition by Dean Miller, Greg Perry

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

17. Making the case for the switch Statement

In This Chapter

Testing multiple cases with switch

Combining break with switch

The if statement is great for simple testing of data, especially if your data tests have only two or three possibilities. You can use if to test for more than two values, but if you do, you have to nest several if statements inside one another, and that can get confusing and hard to maintain.

Consider for a moment how you execute code based on a user’s response to a menu. A menu is a list of options from which to select, such as this one:

What do you want to do?1. Add New Contact2. Edit Existing Contact3. Call Contact4. Text Contact5. Delete Contact6. Quit the ProgramWhat is your choice?

Note

When you create menus ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required