fallthrough语法

2018-06-13 16:46:39 浏览数 (1)

swift 中 switch case 后默认语句后面都会break, 所以当满足某个case之后仍旧想使它匹配下一个case,使用 fallthrough,则不会被截断;

代码语言:javascript复制
case "b","B"
   print("this is b/B")
case "a":
   print("this is a")
   fallthrough
case let x where x.hasSuffix("peper"):
   print("has suffix "   x)
default:
   print("default")
}

0 人点赞