上QQ阅读APP看书,第一时间看更新
The fallthrough statement
Similarly, we may occasionally need the fall-through behavior that C switch statements exhibit. We can do this by adding the fallthrough keyword to a case:
switch a
{
case (let x) where x > 0:
print("a is positive")
fallthrough
case 0..<10:
print("a is single digit")
default:
break
}
With judicious use of these additional matching and control transfer features, we can often write extremely neat code. As usual, with power comes responsibility (if only I had a dollar for every blog post that says that), and it's worth reiterating the point that clarity trumps brevity; less is not always more.