Hi,
I would like to know if the order of the evaluation of the conditions in guard
and if
statements are evaluated in the same order as specified in code ?
Reason for asking
- I have a simple condition followed by a complex (expensive) condition, just wanted to ensure that the complex condition is evaluated only after the simple condition is satisfied.
Question:
- Is the order of evaluation guaranteed both in
guard
andif
statements ? - Or there could be compiler optimisations or other factors that might cause it to be evaluated in a different order ?
Code:
func simpleCondition() -> Bool {
return false
}
func complexCondition() -> Bool {
return true //Assume this is an expensive operation
}
func f1() {
guard simpleCondition(),
complexCondition() else {
return
}
}