[swift-users] Will it be better if `fallthrough` works with `label` in nested `switch - case`?

Zhao Xin owenzx at gmail.com
Fri Oct 14 21:44:17 CDT 2016


I thought below code would work. It didn't.

let count = 1


outerSwitch: switch count {

case 0, 1:

    let buttonId = 0

    switch  buttonId {

    case NSAlertFirstButtonReturn:

        print("do something")

    case NSAlertSecondButtonReturn:

        print("do something")

    case NSAlertThirdButtonReturn:

        print("do something")

        fallthrough outerSwitch // error here

    default:

        fatalError()

    }

default:

    print("do extra things")

}

So I have to use `if - else if - else` instead. I think if `fallthrouh`
works with `label`, the code will be more elegant.

Zhaoxin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161015/826b7bfb/attachment.html>


More information about the swift-users mailing list