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)  //不執行

        }

相關文章
相關標籤/搜索