Basic Use

suggest change
let number = 3
switch number {
case 1:
    print("One!")
case 2:
    print("Two!")
case 3:
    print("Three!")
default:
    print("Not One, Two or Three")
}

switch statements also work with data types other than integers. They work with any data type.Here’s an example of switching on a string:

let string = "Dog"
switch string {
case "Cat", "Dog":
  print("Animal is a house pet.")
default:
  print("Animal is not a house pet.")
}

This will print the following:

Animal is a house pet.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents