Thank you Lantua, is it possible to use a guard statement outside of the context of optionals? For example can I use a guard statement in an if statement?
Guard statement can be used anywhere. The problem in your code is continue.
continue will go to the next loop, so you need a loop to go to, hence the warning.
for a in array {
continue // go to the next `for` iteration.
}
guard is essentially a reverse if, so any where if is permitted, so will guard.
guard value else {
// We go in here ONLY if `value` is FALSE
}
The main difference is that you need to get out of the current scope, using `continue`, `break`, or `return`. This is because `guard` is designed to handle something that make “the code unable to go on”.