Module 7: Switch, While, and Do-While

CMPS 162: Introduction to Programming


Switch statements are similar to an if statement with many else if branches, but with a nicer syntax as well. One caveat is that once a case matches, the code for all subsequent cases will also be executed unless one specifically breaks out of the switch statement. While loops are an alternative to for loops that are sometimes a better fit (e.g., when testing for a boolean) and come in two different forms.

Module Objectives

  • Show how to start switch statements
  • Show how to complete switch statements
  • Illustrate while loops
  • Illustrate do…while loops

Learning Resources

  • Module 7 Readings: Chapters 39 thru 42 from Myers

Learning Activities

  • Midterm
  • Module 7 Assignment: Interactive Coding Exercises 39 thru 42

For Further Study

Leave a Reply

Your email address will not be published. Required fields are marked *