Swift Program to Use Enumeration Constants Using the Switch Statement

You are currently viewing Swift Program to Use Enumeration Constants Using the Switch Statement

Swift program to use enumeration constants using the switch statement

// Swift program to use enumeration constants using
// the switch statement

import Swift

enum Colors:Int {
    case RED
    case GREEN
    case BLUE
    case WHITE
}

var FavColor = Colors.GREEN

switch FavColor {
    case .RED:
    print("Red")

    case .GREEN:
    print("Green")
    
    case .BLUE:
    print("Blue")
    
    case .WHITE:
    print("White")
}

Output

Green

...Program finished with exit code 0
Press ENTER to exit console.

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply