The switch Statement
The type of if-else statement chain you encountered in the last program example—with the value of a variable successively compared against different values—is so commonly used when developing programs that a special program statement exists in the Objective-C language for performing precisely this function. The name of the statement is the switch statement, and its general format is as follows:
switch ( expression ){ case value1: program statement program statement ... break; case value2: program statement program statement ... break; ... case valuen: program statement program statement ... break; default: program ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access