vendredi 10 juin 2016

Swift use of break in guard statement

I'm trying to use break in an guard statement, but the compiler tells me

'break' is only allowed inside a loop, if, do, or switch

Is possible to write something like in this snippet?

   func test(string: String?, x: Int) {
        print("Function Scope BEGIN")
        if x > 4 {
            guard let pr = string else { break }
            print(pr)
        }
        else {
            print("Not")
        }
        print("Function Scope END")
    }

Aucun commentaire:

Enregistrer un commentaire