Swift中Switch语句中的break 官网
在Swift的 Switch 语句中, break 用于阻止代码继续向下执行。在 Switch 语句里,每个 case 执行完后默认会跳出 Switch ,不过如果想提前结束某个 case 的执行,可以使用 break 。 let num = 2switch num {case 1: print(One)case 2: if true { break } print(Two)default: print(Other)} 这里当 num 为 2 时,由于 if 条件成立执行 break ,不会输出 Two。 Swift的 Switch 语句和其他语言不同,不需要在每个 case 结尾添加 break 来防止贯穿,除非有特殊需求。