ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Swift program to create case with multiple values in the switch block

Here, we are going to learn how to create case with multiple values in the switch block in Swift programming language?
Submitted by Nidhi, on June 02, 2021

Problem Solution:

Here, we will create a case with multiple values in the switch block. Values in created case separated by a comma "," operator.

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.

// 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.

Swift Switch Statement Programs »

ADVERTISEMENT
ADVERTISEMENT




Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.