#29: Fallthrough
Question
// Swift Quiz
— objc.io (@objcio) September 4, 2019
let number = 5
var result = 0
switch number {
case 1...5:
result = 1
fallthrough
case 2:
result = 2
case 5:
result = 3
default:
result = 4
}
// What's the value of result?
Solution
Solution: 2
— objc.io (@objcio) September 5, 2019
The fallthrough keyword is an opt-in way to get "case fallthrough" in Swift, that is: a fallthrough means the body of the next case gets executed.https://t.co/s7500CWmAg