Swift之fallthrough

在swift的switch语句中使用fallthrough,如同C中的switch的不使用break操做,可是又有不同,即跳出当前,继续向下执行,而不是执行完当前再向下执行.具体以下代码swift

let i = 4this

        var testStr = "this is"it

        switch i {test

        case 1:co

            testStr += " contain one"cas

            

        case 4:let

            

            testStr += " contain four"

            fallthrough

        case 5:

            fallthrough

            testStr += " contain five"

             print(testStr)  //this is contain four

 

        default:

            print(testStr)  //不执行

        }

相关文章
相关标签/搜索