Swift Switch Case

In this tutorial you will learn about the Swift Switch Case and its application with practical example.

Swift Switch Case Statement

The switch statement is simplified form of the nested if … else if statement , it helps to avoid long chain of if..else if..else statements. A switch statement evaluates an expression against multiple cases in order to identify the block of code to be executed.

Swift Switch Case Flow Diagram

switch-statement-flowchart

 

Syntax:-

Example:-

In the above swift program we have an integer constant dayOfWeek with initial value of 5, and we pass this variable as expression to following switch statement, value of dayOfWeek is tested with multiple cases to identify the block of code to be executed.

When we run the above swift program, will see the following output –

Output:-

swift_switch_case_statement

In this tutorial we have learn about the Swift Switch Case and its application with practical example. I hope you will like this tutorial.