Switch Statement in Swift
Level 2133 keystrokes
Uses switch with several values per case to classify "Mon" as a weekday and prints "Weekday".
Swift code
// The day to classify1let day = "Mon"// Compares day with each case from top to bottom2switch day {// A case can list several values separated by commas; "Mon" matches here3case "Mon", "Tue", "Wed": // Only this case runs; Swift does not fall through, so no break is needed4 print("Weekday")5case "Sat", "Sun":6 print("Weekend")// switch must be exhaustive, so a String switch needs default7default:8 print("Other")9}Output
Weekday
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Swift code and how often they appear.
"× 18,× 3:× 3(× 3)× 3{× 1}× 1=× 1