In this post, We will share a Switch Statement in Swift programming with an example and real-time output. This is a very basic program in Swift programming language. If you are Swift beginners or want to start learning Swift programming language, then this program will help you to understand the basic Swift programming.
Copy the below program and create a file named “SwitchStatement.swift” and execute it.
The syntax of the switch statement in the Swift programming language
switch statement syntax is:
1 2 3 4 5 6 7 8 |
switch variable/expression { case value1: //your statements case value2: //your statements default: //your default statements } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#define variables let dayOfWeek = 5 switch dayOfWeek { case 1: print("Sunday") case 2: print("Monday") case 3: print("Tuesday") case 4: print("Wednesday") case 5: print("Thursday") case 6: print("Friday") case 7: print("Saturday") default: print("Invalid day") } |
Thursday
Liked this program? Do Like & share with your friends.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.