When guard fails the condition, they exit the closure. However, what confuses me what is considered to be a block the guard exits out of?
For example, if I have the following:
func doThing() {
while ... {
for ... {
if ... {
guard ... else { return }
}
}
}
}
Does the guard exit just the if, for, while, or entire func?
What is the actual rule because I've read block and closure terms used interchangeably when defining what the guard exits out of, but each term implicate things differently.
returnstatement used to exit from nearest closure (function in your case) with result value (Voidby default), no matter how deep you are in cycles orifconditions. Probably you mixed upreturnwithbreak.However, you may also use
break,continueorthrowstatement inelseclause ofguardstatement. If you usebreakstatement, for example, you end execution of nearest cycle orswitchstatement, or, if you mark cycle/if/switchby label and usebreakfollowed with that label, you exit marked statement.