No, that would be equivalent to solving the halting problem, while compiler can't do even this:
func foo(_ condition: Bool) -> Int {
let x: Int
if condition { x = 42 }
if !condition { x = 24 } // 🛑 Immutable value 'x' may only be initialized once
return x // 🛑 Constant 'x' used before being initialized
}
Do you promise to "break" only when "bang" is assigned? And not assign "bang" more than once? Compiler won't be able to check, so it's up to you.
Typically you'd do one of these:
1. var bang: String = ""
and then reassign (exactly once), compiler will not check that you did.
2. var bang: String!
and then reassign (exactly once). compiler will still not check that you did, but you'd at least crash in runtime if you forgot to assign at least once.
3. var bang: String! { // "set-only-once" property
didSet {
precondition(oldValue == nil && bang != nil)
}
}
this will crash at runtime in cases when you reassign the property more than once
4.
bang = f(...)
func f(....) {
while true {
if ... { return "..." }
....
}
}
i.e. refactor the while loop into a (local) function. This one won't work in "init" though.
This reminds me we haven't finished yet with the multi-statement-if-switch-do-expressions pitch. Loops were not part of that pitch but were brought up during the discussion.