The source code to create a case with multiple values in the switch block is given below. The given program is compiled and executed successfully.
// Swift program to create case with
// multiple values in switch block
var Num:Int=2;
switch Num {
case 1:
print("One");
case 2,3:
print("Two or Three");
case 4:
print("Four");
case 5:
print("Five");
case 6:
print("Six");
case 7:
print("Seven");
default:
print("Unknown number");
}
Output:
Two or Three
...Program finished with exit code 0
Press ENTER to exit console.
Explanation:
In the above program, we imported a package Swift to use the print() function using the below statement,
import Swift;
Here, we implemented a case with multiple values in the switch block and, we also created an integer variable Num with initial value 2. Then we printed the appropriate message based on the value of the variable Num on the console screen.
Program/Source Code:
The source code to create a case with multiple values in the switch block is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we imported a package Swift to use the print() function using the below statement,
Here, we implemented a case with multiple values in the switch block and, we also created an integer variable Num with initial value 2. Then we printed the appropriate message based on the value of the variable Num on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer