December 2013
Intermediate to advanced
132 pages
1h 58m
English
CHAPTER 15
![]()
Switch Statements
Switch Statements Defined
Switch statements are used to execute code based on the value of an integer. To make a switch statement work, you need to define a level variable and then you need to write a code block for each possible value of the level variable that you expect.
For this chapter, let’s assume you are writing code to help you do some geometry work. You have different shapes that you need to work with and you want to calculate the area of each shape. You can keep track of what type of shape you are working with by using an NSInteger variablelike shape.
NSInteger shape = 0;
Each value of the NSInteger shape ...
Read now
Unlock full access